I am using a CollectionViewSource
and have set up the CollectionViewSource.SortDescription
property in xaml for sorting the collection on a particular property.
However, now I have a case wherein if certain condition is true, or collection is of particular type, I don't need to apply the sorting, but rather to just bind the collection as it is from the view model.
I don't want to move the sorting out of XAML to view model, since it complicates the matter. I want to leave sorting to CollectionViewSource.SortDescription
, however want to know if there is a way to turn it off based on some flag. E.g. I can expose a property IgnoreSort
in my view model and just somehow consume it to turn the CollecitonViewSource
sorting off.
Following is the xaml code-
Resource:
<UserControl.Resources>
<CollectionViewSource x:Key="PeopleItemsSource" Source="{Binding Department.ActivePeople}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="DisplaySortOrder" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
And here is the control using the resource declared above
<ItemsControl x:Name="peopleitems"
Grid.Row="1"
ItemsSource="{Binding Source={StaticResource PeopleItemsSource}}"/>
Note: Item template is not added here to simplify the xaml.