I am working on a scheduling program in which items have a scheduled date, but the user can elect to override this for a date they choose. To implement this, my Item object uses two properties: ScheduledDate (DateTime) and ActualDate (DateTime?). Therefore, if the ActualDate property is null, the user has not overridden the schedule for this item.
In one of my views, I need to display these items in a ListBox
, sorted by the actual date. The trouble I am having is how to implement a CollectionViewSource
with these two properties.
I know it's not correct, but I need something like this:
<CollectionViewSource x:Key="TransactionsViewSource"
Source="{Binding ElementName=ThisControl,
Path=Items}">
<CollectionViewSource.SortDescriptions>
<cm:SortDescription PropertyName="ActualDate ?? ScheduledDate"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
(ThisControl is the name of the UserControl
that hosts the ListBox
.)
If I add a second SortDescriptor (like below), I get a list sorted by ActualDate, then by Scheduled Date, which groups all of the overridden items together. This is not the desired behavior.
<CollectionViewSource x:Key="TransactionsViewSource"
Source="{Binding ElementName=ThisControl,
Path=Items}">
<CollectionViewSource.SortDescriptions>
<cm:SortDescription PropertyName="ActualDate"/>
<cm:SortDescription PropertyName="ScheduledDate"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
Thanks.