title: Trigger Filter on CollectionViewSource
body: <p>I am working on a WPF desktop application using the MVVM pattern.</p>
  
  <p>I am trying to filter some items out of a <code>ListView</code> based on the text typed in a <code>TextBox</code>. I want the <code>ListView</code> items to be filtered as I change the text.</p>
  
  <p><strong>I want to know how to trigger the filter when the filter text changes.</strong></p>
  
  <p>The <code>ListView</code> binds to a <code>CollectionViewSource</code>, which binds to the <code>ObservableCollection</code> on my ViewModel. The <code>TextBox</code> for the filter text binds to a string on the ViewModel, with <code>UpdateSourceTrigger=PropertyChanged</code>, as it should be.</p>
  
  <pre><code>&lt;CollectionViewSource x:Key="ProjectsCollection"
                        Source="{Binding Path=AllProjects}"
                        Filter="CollectionViewSource_Filter" /&gt;
  
  &lt;TextBox Text="{Binding Path=FilterText, UpdateSourceTrigger=PropertyChanged}" /&gt;
  
  &lt;ListView DataContext="{StaticResource ProjectsCollection}"
            ItemsSource="{Binding}" /&gt;
  </code></pre>
  
  <p>The <code>Filter="CollectionViewSource_Filter"</code> links to an event handler in the code behind, which simply calls a filter method on the ViewModel.</p>
  
  <p>Filtering is done when the value of FilterText changes - the setter for the FilterText property calls a FilterList method that iterates over the <code>ObservableCollection</code> in my ViewModel and sets a <code>boolean</code> FilteredOut property on each item ViewModel.</p>
  
  <p>I know the FilteredOut property is updated when the filter text changes, but the List does not refresh. The <code>CollectionViewSource</code> filter event is only fired when I reload the UserControl by switching away from it and back again.</p>
  
  <p>I've tried calling <code>OnPropertyChanged("AllProjects")</code> after updating the filter info, but it did not solve my problem.
   ("AllProjects" is the <code>ObservableCollection</code> property on my ViewModel to which the <code>CollectionViewSource</code> binds.)</p>
  
  <p>How can I get the <code>CollectionViewSource</code> to refilter itself when the value of the FilterText <code>TextBox</code> changes?</p>
  
  <p>Many thanks</p>