我有一个从数据集中提取数据的 WPF 项目。在一个特定的视图中,我有一个网格,我想显示数据的过滤版本
我读过我无法过滤 BindingListView 但这是一个 CollectionViewSource
我的代码是这样的: -
Private Sub UserControl_Loaded_1(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
Dim _ds As CantileverDataSet
Dim _carcasseTableAdapter As CantileverDataSetTableAdapters.MaterialsTableAdapter
Dim _carcasseViewSource As CollectionViewSource
_ds = CType(Me.FindResource("CantileverDataSet"), CantileverDataSet)
_carcasseTableAdapter = New CantileverDataSetTableAdapters.MaterialsTableAdapter
_carcasseTableAdapter.Fill(_ds.Materials)
_carcasseViewSource = CType(Me.FindResource("MaterialsViewSource"), CollectionViewSource)
AddHandler _carcasseViewSource.Filter, AddressOf CarcasseFilter
End Sub
Private Sub CarcasseFilter(ByVal sender As System.Object, ByVal e As FilterEventArgs)
'Accept everything for now
e.Accepted = True
End Sub
我得到的错误是
'System.Windows.Data.BindingListCollectionView' 视图不支持过滤。
- 如果我做 _carcasseViewSource.GetType 我得到 CollectionViewSource
- 如果我做 _carcasseViewSource.View.GetType 我得到 BindingListCollectionView
就好像它将我的 _carcasseViewSource 视为 BindingListCollectionView 一样
这是网格的 XAML 以防万一
<Grid x:Name="CarcasseGrid" DataContext="{StaticResource MaterialsViewSource}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Material Code:" Grid.Column="0" Grid.Row="0"/>
<TextBox x:Name="MaterialCodeTextBox" Grid.Column="1" Grid.Row="0" Text="{Binding MaterialCode, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
<Label Content="Name:" Grid.Column="0" Grid.Row="1"/>
<TextBox x:Name="NameTextBox" Grid.Column="1" Grid.Row="1" Text="{Binding Name, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
</Grid>