0
我有一個從數據集中繪製數據的WPF項目。在一個特定視圖我有一個網格,我想表明WPF篩選CollectionViewSource
我讀過,我不能過濾一個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>
任何想法,將不勝感激