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

  • Home
  • SEARCH
  • 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 7582511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:27:08+00:00 2026-05-30T18:27:08+00:00

A technique I have used for a long time to do sorting in WPF

  • 0

A technique I have used for a long time to do sorting in WPF is to create a CollectionViewSource and specifying SortDescriptions, eg

<Window.Resources>
    <CollectionViewSource x:Key="testView">
        <CollectionViewSource.SortDescriptions>
            <cm:SortDescription PropertyName="FirstName" Direction="Descending"></cm:SortDescription>
            <cm:SortDescription PropertyName="FamilyName"></cm:SortDescription>
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

This has worked perfectly for everything I’ve thrown at it except with the DataGrid. It appears to work fine the first time through but if I change the data then the grid kills the sorting. It even kills it for other controls that use the same CollectionViewSource. I’ve created a sample project here

http://www.mikesdriveway.com/misc/GridSortIssue.zip

To test this issue run the project and click the Refresh Data button. Notice that the order of items changes. This only happens once, to test again stop and run the project again. Now delete the ItemsSource from the DataGrid and run the project again. This time when you click the Refresh Data button nothing happens, this means the sorting remains the same. Somehow the grid is killing the sorting in the CollectionViewSource. Is this a bug?

Cheers,
Michael

  • 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-05-30T18:27:09+00:00Added an answer on May 30, 2026 at 6:27 pm

    That is rather odd, from what i can tell the SortDescription of the underlying View get cleared out when the source is changed, so if the SortDescriptions of the CVS are not re-applied there is no sorting anymore.

    One workaround would be to “reset” the SortDescriptions:

    var cvs = (CollectionViewSource)Resources["testView"];
    var descriptions = cvs.SortDescriptions.ToArray();
    cvs.SortDescriptions.Clear();
    foreach (var descripton in descriptions) cvs.SortDescriptions.Add(descripton);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have a technique for generating SQL table create (and data insert) commands
I know it can be done in Java, as I have used this technique
The technique I have used to hide/unhide a div is as follows: $(# +
What technique have these guys used to get a nice melow dropshadow on the
Many times I have used an css technique that I learned by myself. When
I have seen the following href used in webpages from time to time. However,
I want to create tree structure using web service. I have used bottom up
I have seen two commonly used techniques for adding the directory of the file
What is the proper technique to have ThreadA signal ThreadB of some event, without
I have heard the 'shard' technique mentioned several times with regard to solving scaling

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.