我有一个ObservableCollection
个对象,其中一个AcquiredDateGroup
个称为项。 AcquiredDateGroup
的属性之一是称为特征的Feature
对象的数组。
我有绑定到ObservableCollection的相当复杂的树视图。 AcquiredDateGroup
的属性用于分组,Feature数组用于树中的最终叶子。我想根据其属性之一来过滤功能数组,可以说IsSelected
,但到目前为止,我发现的所有示例都使用CollectionView和CollectionViewSource之类的方法过滤父ObservableCollection
。
是否可以直接过滤此数组?
AcquiredDateGroup类
class AcquiredDateGroup : INotifyPropertyChanged
{
public Feature[] features { get; set; }
public List<Item> items { get; set; }
public DateTime acquired { get; set; }
public string date
{
get
{
return acquired.Date.ToString("MMM dd,yyyy");
}
}
public IEnumerable<object> Items
{
get
{
foreach (var item in items)
{
yield return item;
}
}
}
}
功能类
public class Feature
{
public _Links1 _links { get; set; }
public object[] _permissions { get; set; }
public bool IsSelected { get; set; } = false;
public string id { get; set; }
}
非常简化的视图摘录。 :
<TreeView Name="SearchResults" Grid.Row="3" Grid.Column="0" IsEnabled="{Binding TreeEnabled}" ItemsSource="{Binding Items}" >
<DataTemplate DataType="{x:Type model:Feature}">
<CheckBox IsChecked="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding IsSelected,Converter={StaticResource SelectCheckIconVisibiltyConverter }}" IsEnabled="{Binding _permissions,Converter={StaticResource PermissionsConverter}}" Margin="5,0" Focusable="False" VerticalAlignment="Center" HorizontalAlignment="Left" ToolTip="Select" Tag="{Binding Path=id}">
</CheckBox>
MVVM摘录:
private ObservableCollection<Model.AcquiredDateGroup> _items;
public ObservableCollection<Model.AcquiredDateGroup> Items
{
get
{
if (_items == null)
{
_items = new ObservableCollection<Model.AcquiredDateGroup>();
}
return _items;
}
set
{
_items = value;
OnPropertyChanged("Items");
}
}