wpf - 更改 XamDatGrid 的筛选器属性

标签 wpf mvvm infragistics xamdatagrid

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

经过大量研究后我无法找到它,如果有人可以帮助我找到我错过的东西,那就太好了。

最佳答案

如果您希望在您的 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
}

然后在您的 View 中,您只需 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"/>

关于wpf - 更改 XamDatGrid 的筛选器属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12148432/

相关文章:

c# - MVVM WPF Multibinding 不适用于命令参数

wpf - 如何在 Prism 框架中加载实际 shell 之前显示登录屏幕

c# - 选中复选框时更改 wpf 数据网格行背景颜色

javascript - infragistics igeditor 的 onsubmit 验证选项不起作用

angular - 将超链接添加到 igx-grid 中的列

javascript - 单击按钮保存客户端生成的图像

c# - 在 C++ 背景下迁移到 WPF 和 C# 的资源

wpf - 增加WPF GridSplitter鼠标抓取阈值

wpf - 绑定(bind)到 ObservableCollection MVVM 的 TabControl

silverlight - MVVM Light工具包的性能不会受到影响吗?