从ICollectionView CurrentItem的Property创建CollectionViewSource

时间:2013-02-28 00:51:53

标签: c# wpf data-binding mvvm collectionviewsource

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

在我的VM中,我有ICollectionView,它是UserControls的DataContext。

public ICollectionView Clients

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

ItemsSource="{Binding Clients/Loans}"

但我的问题是排序。我想通过属性对贷款进行排序,所以我尝试从该列表创建一个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>

在XAML中是否可以在VM中创建新属性?

1 个答案:

答案 0 :(得分:0)

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

相关问题