我知道一个集合视图源中的一个过滤器,但是当我在一个集合源中使用多个过滤器时。最后过滤器只能正常工作。请帮我在一个集合视图源中执行多个过滤器。
的Xaml
<Grid>
<DockPanel>
<DockPanel DockPanel.Dock="Top" Height="90">
<TextBlock VerticalAlignment="Center" Margin="0,9" DockPanel.Dock="Left" >Threshold</TextBlock>
<Slider x:Name="Confidencethreshold" Value="14" Margin="0,5" DockPanel.Dock="Left" Width="200"
Minimum="0" Maximum="50"
ValueChanged="Confidencethreshold_ValueChanged_1"
TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="False" SmallChange="1"></Slider>
<StackPanel Orientation="Horizontal" >
<RadioButton x:Name="radioFound" IsChecked="True" Content="Matches" Checked="radioFound_Checked_1" Margin="6" />
<RadioButton x:Name="radioALL" Content="ALL" Checked="radioFound_Checked_1" Margin="6"/>
</StackPanel>
</DockPanel>
<DataGrid Name="DG2" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserSortColumns="True">
<DataGrid.Columns>
<!--<mui:DataGridCheckBoxColumn Header="Silence Reduction" Binding="{Binding P1}"/>-->
<mui:DataGridTextColumn Header="Segment" Binding="{Binding sname}" IsReadOnly="True" />
<!--<mui:DataGridCheckBoxColumn Header="Trimming" Binding="{Binding trim}" />
<mui:DataGridCheckBoxColumn Header="Format Conversion" Binding="{Binding alaw}"/>
<mui:DataGridCheckBoxColumn Header="Recognition" Binding="{Binding recog}" />-->
<!--<mui:DataGridComboBoxColumn Header="Status" SelectedItemBinding="{Binding Status}" ItemsSource="{Binding Source={StaticResource myEnum}}" />-->
<mui:DataGridTextColumn Header="Key" Binding="{Binding key}" IsReadOnly="True" />
<!--<mui:DataGridTextColumn Header="Confidence" Binding="{Binding conf}" IsReadOnly="True" SortDirection="Ascending" SortMemberPath="{Binding conf}" />-->
<mui:DataGridTextColumn Header="Confidence" Binding="{Binding conf}" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</Grid>
And in c#
MainWindow w1 = (MainWindow)Window.GetWindow(this);
cvs = new CollectionViewSource();
cvs.Source = w1.allresults;
cvs.Filter += cvs_Filter;
DG2.DataContext = cvs;
void cvs_Filter(object sender, FilterEventArgs e)
{
KeysFound t = e.Item as KeysFound;
if (t != null)
// If filter is turned on, filter completed items.
{
if (t.conf < Confidencethreshold.Value)
e.Accepted = false;
else
{
e.Accepted = true;
}
}
}
答案 0 :(得分:-2)
您可以使用ICollectionView而不是datagrid源的CollectionViewSource。以下链接可能有所帮助..