我試圖將篩選器設置更改爲「contains」而不是「開始於」XamDataGrid內部,是否有允許實現該功能的任何屬性?更改XamDatGrid的篩選器屬性
經過大量研究後,我無法找到它,如果有人能幫我找到是否有我錯過的東西,那該多好。
我試圖將篩選器設置更改爲「contains」而不是「開始於」XamDataGrid內部,是否有允許實現該功能的任何屬性?更改XamDatGrid的篩選器屬性
經過大量研究後,我無法找到它,如果有人能幫我找到是否有我錯過的東西,那該多好。
得到我需要的財產,謝謝大家。
它是這樣的,
<igDP:Field Name="Description">
<igDP:Field.Settings>
<igDP:FieldSettings
AllowGroupBy="True"
AllowEdit="True"
AllowRecordFiltering="True"
FilterOperatorDefaultValue="Contains"/>
</igDP:Field.Settings>
</igDP:Field>
如果你寧願在你的視圖模型篩選,這裏是一個演示瞭如何使用一個例子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"/>
謝謝Brian,會試試你的建議.. – user1521554
它可能不是您正在尋找的答案,但您可以使用「ICollectionView」直接過濾數據源。這允許更多的靈活性,因爲它不依賴於UI實現(您是否使用MVVM?)。如果您對這種方法感興趣,我可以添加一些示例代碼的答案。 –
是的,我正在使用MVVM,但過濾數據源會有幫助的是我想知道的。 過濾功能只是讓觀衆很容易地找到記錄,但它始於很多角色,不幸的是名稱的一部分,我尋找的原因包含。 – user1521554