Filtering an ObservableCollection?

后端 未结 3 2007
[愿得一人]
[愿得一人] 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:27

    Why it does not work:

    listBox1.ItemsSource = Words.Where(w => w.Contains(":"));
    

    Your are not binding the ObservableCollection but the IEnumerable generated by Linq. This new "list" does not notify the ListBox about changes in the list.

提交回复
热议问题