Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:01:20+00:00 2026-06-07T05:01:20+00:00

In an MVVM environment, I have a ListCollectionView bound to an ObservableCollection. My Foo

  • 0

In an MVVM environment, I have a ListCollectionView bound to an ObservableCollection. My Foo objects have a IsDefault property to them, and my requirement is to have that item first in the list, and the rest should be alpha-sorted.

So this code only sorts the whole list, obviously:

_list = new ListCollectionView(Model.Data);
        _list.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

Not sure how to make sure that item #3 (for example, which has IsDefault=true) be at the top of the list, and the rest (that have IsDefault=false) be alpha sorted.

Is this a case to use _list.CustomSort and implement IComparer in some way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:01:22+00:00Added an answer on June 7, 2026 at 5:01 am

    Yes, this is exactly the case where you need to use ListCollectionView.CustomSort. Custom sorting is mutually exclusive with using SortDescriptions; the documentation for the former is explicit about this:

    Setting this property clears a previously set SortDescriptions value.

    So what you need to do is define an IComparer and use it to sort the view:

    class CustomComparer : IComparer
    {
        public int Compare (object lhs, object rhs)
        {
            // missing: checks for null, casting to Model.Data, etc etc
    
            if (lhsModelData.IsDefault && rhsModelData.IsDefault) {
                return lhsModelData.Name.CompareTo(rhsModelData.Name);
            }
            else if (lhsModelData.IsDefault) {
                return -1;
            }
            else if (rhsModelData.IsDefault) {
                return 1;
            }
            else {
                return lhsModelData.Name.CompareTo(rhsModelData.Name);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MVVM style I have successfully bound an ObservableCollection<string> to a ListBox , showing
I'm learning MVVM. I have my View filling two comboboxes from ObservableCollection properties in
I have a simple MVVM application. It contains a property, which I will change
I am using the MVVM model. I have a dependency property, a boolean, called
Using MVVM and EF...I have a datagrid binding to a View Model (using ObservableCollection).
Using MVVM Light, I have two WPF applications that reference a common Views library.
I have a MVVM setup that creates a View on my MainWindow. I am
I'm doing MVVM where a DataGrid is bound to an ObservableCollection with a DeleteItemCommand
I have a silverlight mvvm application that loads main view with 2 user controls
I'm using MVVM via Caliburn Micro on WP7. I have a popup that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.