2012-08-27 55 views
0

我试图将筛选器设置更改为“contains”而不是“开始于”XamDataGrid内部,是否有允许实现该功能的任何属性?更改XamDatGrid的筛选器属性

经过大量研究后,我无法找到它,如果有人能帮我找到是否有我错过的东西,那该多好。

+0

它可能不是您正在寻找的答案,但您可以使用“ICollectionView”直接过滤数据源。这允许更多的灵活性,因为它不依赖于UI实现(您是否使用MVVM?)。如果您对这种方法感兴趣,我可以添加一些示例代码的答案。 –

+0

是的,我正在使用MVVM,但过滤数据源会有帮助的是我想知道的。 过滤功能只是让观众很容易地找到记录,但它始于很多角色,不幸的是名称的一部分,我寻找的原因包含。 – user1521554

回答

1

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

它是这样的,

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

如果你宁愿在你的视图模型筛选,这里是一个演示了如何使用一个例子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"/> 
+0

谢谢Brian,会试试你的建议.. – user1521554