【问题标题】:Change the filter properties of XamDatGrid更改 XamDatGrid 的筛选器属性
【发布时间】:2012-08-27 19:36:14
【问题描述】:

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

经过大量研究,我找不到它,如果有人能帮我找到我错过的东西,那就太好了。

【问题讨论】:

  • 这可能不是您要寻找的答案,但您可以使用ICollectionView 直接过滤您的数据源。这允许更大的灵活性,因为它不依赖于 UI 实现(您使用的是 MVVM 吗?)。如果您对这种方法感兴趣,我可以使用一些示例代码添加答案。
  • 是的,我正在使用 MVVM,但我想知道过滤数据源是否会有所帮助。过滤功能只是为了让查看者轻松找到记录,但它以大量字符开头,不幸的是必须成为名称的一部分,这就是我寻找包含的原因。

标签: wpf mvvm infragistics xamdatagrid


【解决方案1】:

如果您更愿意在 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
}

然后在您的视图中,您只需将 TextBox DataBind 到 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"/>

【讨论】:

    【解决方案2】:

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

    事情是这样的,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2016-01-29
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2018-10-06
      相关资源
      最近更新 更多