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
You should use the ICollectionView.Filter
property:
ICollectionView view = CollectionViewSource.GetDefaultView(Words);
view.Filter = WordFilter;
...
bool WordFilter(object o)
{
string w = (string)o;
return w.Contains(":")
}
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.
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(":");
}