如何在加载视图时选择DataGrid筛选器的筛选器作为默认筛选器?

时间:2015-11-12 08:56:48

标签: c# wpf filter datagrid

我尝试在加载视图时选择DataGrid过滤器的过滤器作为默认过滤器 我已经从github https://github.com/basio/veropos/blob/master/Lib/DataGridFilterLibrary/Themes/Generic.xaml

添加到我的项目数据网格过滤器库

    <Style.Resources>
        <support:EnumDisplayer Type="{x:Type support:FilterOperator}" x:Key="filterOperators">
            <support:EnumDisplayEntry EnumValue="Undefined" DisplayString=""/>
            <support:EnumDisplayEntry EnumValue="LessThan" DisplayString="&lt;"/>
            <support:EnumDisplayEntry EnumValue="GreaterThan" DisplayString="&gt;"/>
            <support:EnumDisplayEntry EnumValue="Equals" DisplayString="="/>    
            <support:EnumDisplayEntry EnumValue="Like" DisplayString="" ExcludeFromDisplay="True"/>
            <support:EnumDisplayEntry EnumValue="Between" DisplayString="" ExcludeFromDisplay="True"/>
            <support:EnumDisplayEntry EnumValue="LessThanOrEqual" DisplayString="&lt;="/>
            <support:EnumDisplayEntry EnumValue="GreaterThanOrEqual" DisplayString="&gt;="/>
        </support:EnumDisplayer>

它对我的工作非常好,

目前没有从列表中选择过滤器, 但我想选择过滤器&#34;等于&#34;作为项目启动时的默认过滤器 EnumDisplayEntry EnumValue =&#34; Equals&#34; DisplayString =&#34; =&#34;

如何做到这一点!!

谢谢

1 个答案:

答案 0 :(得分:0)

If you only want to change a single instance, then I suggest you create a style with a setter where you set the value of FilterCurrentData.Operator to Equals, and use that style on the column you're trying to filter.

Disclaimer: This is notepad code, but it should serve you as a guide:

<Style TargetType="{x:Type local:DataGridColumnFilter}">
    <Style.Resources>
        <support:EnumDisplayEntry EnumValue="Equals" DisplayString="=" x:Key="defaultFilterOperatorEquals" />
    </Style.Resources>
    <Setter Property="FilterCurrentData.Operator" Value="{StaticResource defaultFilterOperatorEquals}" />
</Style>

Good luck!