更改XamDatGrid的过滤器属性

时间:2012-08-27 19:36:15

标签: wpf mvvm infragistics xamdatagrid

我正在尝试将过滤器设置更改为“包含”而不是在XamDataGrid中“开头”,是否有任何属性允许实现该功能?

经过多次研究后我无法找到它,如果有人能帮助我找到我错过的东西,那就太棒了。

2 个答案:

答案 0 :(得分:2)

如果您希望在ViewModel中进行过滤,请举例说明如何使用ICollectionView

public class TestViewModel : INotifyPropertyChanged
{
    private string _filterText;
    private List<string> _itemsList;

    public TestViewModel()
    {
        _itemsList = new List<string>() { "Test 1", "Test 2", "Test 3" };
        this.Items = CollectionViewSource.GetDefaultView(_itemsList);
        this.Items.Filter = FilterItems;
    }

    public ICollectionView Items { get; private set; }

    public string FilterText
    {
        get { return _filterText; }
        set
        {
            _filterText = value;
            Items.Refresh();
            this.RaisePropertyChanged("FilterText");
        }
    }

    private bool FilterItems(object item)
    {

        return this.FilterText == null || item.ToString().Contains(this.FilterText);
    }


    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string propName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
    #endregion
}

然后在您的视图中,您只需DataBind TextBox到FilterText属性,ItemsSource或Grid到Items属性(在这里用ListBox演示):

<TextBox x:Name="ItemsFilter" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" Margin="10" VerticalAlignment="Center"/>
<ListBox x:Name="ItemsList" ItemsSource="{Binding Items}" Grid.Row="1" Width="200" Margin="10" HorizontalAlignment="Left"/>

答案 1 :(得分:1)

获得了我需要的财产,谢谢大家。

就是这样,

    <igDP:Field Name="Description">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings
AllowGroupBy="True"
AllowEdit="True"
AllowRecordFiltering="True"
FilterOperatorDefaultValue="Contains"/>                                        
                                </igDP:Field.Settings>    
                            </igDP:Field>