c# - WPF - CollectionViewSource Custom Sorting: Sort items within the groups, without sorting the groups themselves -


simple question, except fact answer seems not exist. i've created custom sorting method collectionviewsource sorts collection groups in specific order. want sort items within groups alphabetically, without altering order of groups themselves.

i know using sortdescriptions, sorting property name followed sortdescrpiton property name sort items groups , sort items in said groups. not find such implementation custom sorting methods. (note: sortdescriptions not allow custom sorting logic, require)

i tried create 2 sorting methods, 1 sort groups , other alphabetically sort within groups second sort method received ungrouped , unsorted original list of items reason.

xaml collectionviewsource:

 <collectionviewsource x:key="typefacetsbycategory" source="{binding values}">                 <collectionviewsource.groupdescriptions>                     <propertygroupdescription propertyname="category" />                 </collectionviewsource.groupdescriptions>   </collectionviewsource> 

code-behind:

        private void customfacetsort(object sender, routedeventargs e)         {         var fe = sender frameworkelement;          if (fe == null)             return;          var ic = (itemscontrol)fe;         var collection = (listcollectionview)ic.itemssource;          collection.customsort = new sortcategories();         collection.customsort = new sortcategoriesinner();         } 

ideally, second sort method "sortcategoriesinner" sort already-sorted list alphabetically. meaning sortcategories sort collection property named category, sortcategoriesinner sort each item within already-sorted collection alphabetically (using property name). however, sortcategoriesinner receives unsorted, original list when assigned. when inspect collection after assigning sortcategories collection's customsort, collection indeed sorted category. however, when sort collection using sortcategoriesinner right after, list reset before first sort (no longer sorted category).

i tried going items collection groups manually , ordering items in each group alphabetically read won't work.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -