How to update UI according to ICollectionView filter results?

380 views Asked by At

I have two controls - SearchFilter and SearchResult. Filter contains buttons with commands to filter results. Result control has a ListView with a binding to ICollectionView property.

<ListView ItemsSource="{Binding SearchList}">

my modelview with filter logic:

private void FilterTheResults()
{
    var list = (ListCollectionView) SearchList;
    list.Filter = x => ((SearchItem)x).Type == "Video";
}

The problem is as follows:
If I move buttons with commands from the filter control to the result one, my UI is updated after each filter action. But I want to keep these things separate. I have tried to use SearchList.Refresh() and PropertyChanged in FilterTheResults() without success.

1

There are 1 answers

1
Erwin Brandstetter On BEST ANSWER

Editor's note: @Yevhen Martynov edited the answer he found into his question. I put it here as an answer instead.

The solution is the one instance of viewmodel for both controls (through DataContext of Window).