我在ViewModel
public string SearchPattern
{
get
{
return searchPattern;
}
set
{
searchPattern = value;
}
}
private bool UserFilter(object item)
{
return (item as Node).Name.Contains(SearchPattern);
}
public ICollectionView YourFilteredCollection
{
get
{
var source = CollectionViewSource.GetDefaultView(model.Items);
source.Filter = UserFilter;
return source;
}
}
YourFilteredCollection
取决于Model
属性
public ObservableCollection<Node> Items { get; set; }
比我决定过滤Node子项YourFilteredCollectionNodes
public class Node
{
public string Name { get; set; }
public ObservableCollection<Node> Nodes { get; set; }
public ICollectionView YourFilteredCollectionNodes
{
get
{
var source = CollectionViewSource.GetDefaultView(Nodes);
if (source != null)
{
source.Filter = UserFilter;
}
return source;
}
}
private bool UserFilter(object item)
{
//return (item as Node).Name.Contains(SearchPattern);
return true;
}
}
但是在这种情况下,如何从ViewModel中的SearchPattern
项的ViewModel中传递ObservableCollection
?