Filtering an ObservableCollection?

后端 未结 3 1984
[愿得一人]
[愿得一人] 2020-12-06 01:51

When I bind a ListBox directly to an ObservableCollection I get the real-time updates displayed in my ListBox, but as soon as I add other LINQ methods in the mix my ListBox

3条回答
  •  自闭症患者
    2020-12-06 02:31

    Try using the CollectionViewSource like this:

    WordsView = new CollectionViewSource();
    WordsView.Filter += Words_Filter;
    WordsView.Source = Words;
    
    // ...
    void Words_Filter(object sender, FilterEventArgs e)
    {
        if (e.Item != null)
            e.Accepted = ((string)e.Item).Contains(":");
    }
    

提交回复
热议问题