Question

I'm trying to create a CollectionViewSource in XAML from an ICollectionView CurrentItem's Property (related table 1..Many), but I got this error: 'System.Windows.Data.BindingListCollectionView' view does not support sorting.

In my VM I have the ICollectionView, wich is the UserControls's DataContext.

public ICollectionView Clients

Client has Loans property, this is what I'd like to bind to a listbox. It works if I just bind to the CurrentItem's property :

ItemsSource="{Binding Clients/Loans}"

But my problem is the sorting. I want to sort the loans by a property, so I tried to create a CollectionViewSource from that list, but then I got the error above.

<Grid.Resources>
   <CollectionViewSource Source="{Binding Clients/Loans}" x:Key="loan_cv">
       <CollectionViewSource.SortDescriptions>
          <scm:SortDescription PropertyName="CreatedDate" Direction="Descending" />
       </CollectionViewSource.SortDescriptions>
   </CollectionViewSource>
</Grid.Resources>

Is this possible in XAML without creating a new property in VM ?

Was it helpful?

Solution

If someone else has the same problem, I just created an IEnumerable<> object in VM wich can be ordered. And every time when the CurrentItem property changes on the collectionViewSource, I reset the IEnumerable<> object. It works fine, but some time with large objects, it could be slow..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top