【发布时间】:2011-08-14 04:07:52
【问题描述】:
我有一个 DataGrid 绑定到 XAML 中的 CollectionViewSource。
<Window.Resources>
<local:MainWindowViewModel x:Key="ViewModel"/>
<CollectionViewSource x:Key="cvsEntries"
Source="{Binding LogEntriesStore,
Source={StaticResource ViewModel}}"/>
</Window.Resources>
LogEntriesStore 是一个 ObservableCollection(LogEntry 是一个 DTO,在本次讨论中并不重要)
DataGrid 声明为:
<DataGrid AutoGenerateColumns="False"
Margin="0"
Name="dataGrid1"
ItemsSource="{Binding Source={StaticResource cvsEntries}}"
IsReadOnly="True">
现在我在这个 DataGrid 中的各个单元格上都有上下文菜单,以启动过滤请求。右键单击一个单元格,然后选择过滤器以过滤所有行,并仅显示此特定值。
MVVM 收到过滤请求,但现在有点棘手。如何在 CollectionViewSource 上设置过滤器?
(顺便说一句——这本来是带着 Silverlight PagedCollectionView 在公园里散步,但这似乎在 WPF 中不可用,对吗?)
【问题讨论】:
-
这就是你要找的东西bea.stollnitz.com/blog/?p=31
标签: wpf data-binding mvvm