The easiest way I found to do this is create a SearchFilter Property
public string SearchFilter
{
get { return _searchFilter; }
set
{
_searchFilter = value;
OnPropertyChanged("MyTreeViewBoundCollection");
}
}
You bind the search filter to a text box, and everytime the search text box changes you notify that the collection has changed
<TextBox Text="{Binding Path=TemplateDataSchema.SearchFilter, UpdateSourceTrigger=PropertyChanged}"/>
Once the change has occured on the SearchFilter, The WPF binding system will requery the Collection Property, which can then be filtered down
public ObservableCollection<Category> MyTreeViewBoundCollection
{
get {
if (_searchFilter.Trim().Length < 1)
return myObject.Categories;
else
{
ObservableCollection<Category> cats = new ObservableCollection<Category>();
string searchText = _searchFilter.ToLower().Trim();
foreach (Category cat in myObject.Categories)
{
Category tmpCat = new Category(cat.CategoryName);
foreach (Field field in cat.Fields)
{
if (field.DataDisplayName.ToLower().Contains(searchText))
tmpCat.Fields.Add(field);
}
if (tmpCat.Fields.Count > 0)
cats.Add(tmpCat);
}
return cats;
}
}
}
This will only return the filter collection.