从ICollectionView CurrentItem的Property创建CollectionViewSource

时间:2022-06-18 14:04:49

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.

我正在尝试从ICollectionView CurrentItem的Property(相关表1..Many)在XAML中创建一个CollectionViewSource,但是我收到了这个错误:'System.Windows.Data.BindingListCollectionView'视图不支持排序。

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

在我的VM中,我有ICollectionView,它是UserControls的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 :

客户端有Loans属性,这就是我要绑定到列表框的内容。如果我只是绑定到CurrentItem的属性它是有效的:

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.

但我的问题是排序。我想通过属性对贷款进行排序,所以我尝试从该列表创建一个CollectionViewSource,但后来我得到了上面的错误。

<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 ?

如果没有在VM中创建新属性,这在XAML中是否可行?

1 个解决方案

#1


0  

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..

如果其他人有同样的问题,我只是在VM中创建了一个可以订购的IEnumerable <>对象。每当CurrentItem属性在collectionViewSource上发生更改时,我都会重置IEnumerable <>对象。它工作正常,但有时候对于大型物体,它可能会很慢..

#1


0  

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..

如果其他人有同样的问题,我只是在VM中创建了一个可以订购的IEnumerable <>对象。每当CurrentItem属性在collectionViewSource上发生更改时,我都会重置IEnumerable <>对象。它工作正常,但有时候对于大型物体,它可能会很慢..