Hi I created this small example, and I would like to expand it to support Sorting.
public class Country
{
public string Name { get; set; }
public int Sor
You can also use the CollectionViewSource.GetDefaultView
with ListCollectionView
to do the sorting for you, tho you do have to set it for all the child collections as well. I use a linq query to flatten my list to find all the children and set the sorting.
foreach (var structure in Model.Structures.Flatten(t => t.SubItems))
{
var view = CollectionViewSource
.GetDefaultView(structure.SubItems) as ListCollectionView;
if (view != null)
{
view.CustomSort = (x,y) => string.Compare( x, y );
}
}
elsewhere
public static IEnumerable Flatten(
this IEnumerable list, Func> subitems)
{
foreach (T child in list)
{
yield return child;
foreach (T other in Flatten(subitems(child), subitems))
{
yield return other;
}
}
}