Is there a filtering option anywhere in XamDataTree?
Ordinary TreeView has TreeView.Items.Filter, but I couldn't find anything like that here.
Thanks in advance.
Thank you for this example. This definitely helps but the example itself is not working properly. For example, if I type "China" in the filter value, it should show me "Asia" and it's children since "China" is a child node of "Asia". Unfortunately, it just filters everything out.
If you look at the code for filtering with the CollectionView you will see that it only filters the first level. As Jason said before, filtering is done entirely through the CollectionView so the example was just to demonstrate that. You will have to modify the CollectionView filter in order to filter multiple levels.
As an example I have attached an updated version of that sample to filter on additional levels. It is by no means a complete implementation but is meant as guidance/demonstration.
Thank you so much! I'll give this example a try but it looks pretty good as a start.
I was able to use your example to filter the tree children perfectly! The following segment
private void xamDataTree1_Loaded(object sender, RoutedEventArgs e)
view = CollectionViewSource.GetDefaultView(xamDataTree1.ItemsSource);
xamDataTree1.ItemsSource = view;
is a little weird to me though. It looks like you're creating a collection view using the tree's itemSource then you're reassigning the tree's itemSource to the recently created collection view - correct me if I'm wrong but this is essentially saying x=y and then saying y=x. Why is the second line needed? If I remove it, the filter no longer works.
I also tried moving the logic out of the code behind and into a view model. In the process, I did the following:
Although I know this is filtering my tree - I have another control that shares the itemSource and this is properly filtering - the tree itself is not hiding the filtered items. Any thoughts on why?
Scratch my last post. I just understood what the line was for and I was able to get the filtering to work through the view model. Thanks again!