是否可能在一个集合视图源wpf中有多个过滤器

时间:2014-02-17 08:33:18

标签: c# .net wpf filtering collectionviewsource

我知道一个集合视图源中的一个过滤器,但是当我在一个集合源中使用多个过滤器时。最后过滤器只能正常工作。请帮我在一个集合视图源中执行多个过滤器。

的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;

            }


        }
    }

1 个答案:

答案 0 :(得分:-2)

您可以使用ICollectionView而不是datagrid源的CollectionViewSource。以下链接可能有所帮助..

http://social.msdn.microsoft.com/Forums/vstudio/en-US/82cfac7c-d1f6-421c-8891-1149a90c0dd9/wpf-datagrid-one-itemssource-multiple-views-multiple-filters?forum=wpf