
I was wondering if there is an example project anywhere outlining how to bind TreeListView.DataFilter to an object in the ViewModel. The end use case being that the user can add or remove filters at runtime through a custom User Control, so one / many / no filters can be applied.
In my view I am expecting to do something like:
<grids:TreeListView x:Name="ProjectTreeListView"
RootItem="{Binding ProjectTreeRoot}"
IsFilterActive="{Binding ProjectFilterActive}"
DataFilter="{Binding ProjectFilter}">...
Then in the ViewModel have my dependency properties:
private IDataFilter _projectFilter;
public IDataFilter ProjectFilter
{
get => _projectFilter;
set
{
SetProperty(ref _projectFilter, value);
}
}
private bool _projectFilterActive;
public bool ProjectFilterActive
{
get => _projectFilterActive;
set
{
SetProperty(ref _projectFilterActive, value);
}
}
Or even binding to a Collection of IDataFilters, then in the ViewModel I should be able to add filters and activate / deactivate the filter like so:
ProjectFilter = new PredicateFilter(i => ((TreeNodeModel)i).Name.StartsWith("S"));
ProjectFilterActive = true;
When I implement the code above I get a null reference error when the filter is actually called (unfortunately the error is not very clear, I think it's the tree items it isn't getting? ).
Maybe I have missed something simple, maybe I am approaching this entirely incorrectly, please let me know!