相关疑难解决方法(0)

如何通过MVVM为DataGrid ItemSource设置过滤器

我有一个DataGrid绑定到XAML中的CollectionViewSource.

<Window.Resources>
  <local:MainWindowViewModel x:Key="ViewModel"/>
  <CollectionViewSource x:Key="cvsEntries" 
                        Source="{Binding LogEntriesStore, 
                                 Source={StaticResource ViewModel}}"/>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

LogEntriesStore是一个ObservableCollection (LogEntry是一个在本次讨论中不重要的DTO)

DataGrid的声明为:

<DataGrid AutoGenerateColumns="False" 
          Margin="0" 
          Name="dataGrid1" 
          ItemsSource="{Binding Source={StaticResource cvsEntries}}" 
          IsReadOnly="True">
Run Code Online (Sandbox Code Playgroud)

现在,我在此DataGrid中的各个单元格上有上下文菜单,以启动过滤请求.右键单击一个单元格,然后选择过滤器以过滤所有行,并仅显示此特定值.

MVVM获取过滤请求,但现在是棘手的一点.如何在CollectionViewSource上设置过滤器?

(顺便说一句 - 这可能是在公园里用Silverlight散步,PagedCollectionView但似乎在WPF中没有,是吗?)

data-binding wpf mvvm

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

data-binding ×1

mvvm ×1

wpf ×1