title: Implementing a ListView with a CollectionViewSource - Not Refreshing?
body: <p>I'm working on setting up a ListView whose <code>Source</code> property is set to an ivar of a class of mine, called <code>Cat</code>.</p>
  
  <p>Each <code>Cat</code> has an <code>ObservableCollection</code> of <code>Trait</code> objects:</p>
  
  <pre><code>private ObservableCollection&lt;Trait&gt; _traits = new ObservableCollection&lt;Trait&gt;();
  
  public ObservableCollection&lt;Trait&gt; Traits
  {
  get
      {
          return _traits;
      }
  }
  
  public void AddTrait(Trait t)
  {
      _traits.Add(t);
      // Is this redundant? Is one better than the other?
      this.OnPropertyChanged("_traits");
      this.OnPropertyChanged("Traits");
  }
  
  public IEnumerator&lt;Object&gt; GetEnumerator()
  {
      return _traits.GetEnumerator();
  }
  </code></pre>
  
  <p>And then I'm assigning the <code>Source</code> property to this <code>Traits</code> collection:</p>
  
  <pre><code>this.CollectionViewSource.Source = CurrentCat.Traits;
  </code></pre>
  
  <p>This works properly, and the <code>Trait</code> objects are properly displayed in my <code>ListView</code>.</p>
  
  <p><strong>The issue</strong> is that changes to this underlying <code>_traits</code> collection do not cause the UI to update properly. For example, this:</p>
  
  <pre><code>void AddTraitButton_Click(object sender, RoutedEventArgs e)
  {
      if (this.CurrentCat != null)
      {
          this.CurrentCat.AddTrait(new Trait());
      }
  }
  </code></pre>
  
  <p>Doesn't seem to have any effect <em>immediately</em> in the UI, but if I reset the <code>Source</code> property like so:</p>
  
  <pre><code>var oldSource = this.CollectionViewSource.Source;
  this.CollectionViewSource.Source = null;
  this.CollectionViewSource.Source = oldSource;
  </code></pre>
  
  <p>Then the <code>ListView</code> updates properly. But, I'm sure there must be something that I'm missing, as I'd like for the UI to update upon the addition/removal of an item.</p>
  
  <p><strong>Edit:</strong> The <code>CollectionViewSource</code> is being applied to the <code>ListView</code> in my XAML file:</p>
  
  <pre><code>&lt;CollectionViewSource x:Name="CollectionViewSource" x:Key="CollectionViewSource" /&gt;
  
  ...
  
  &lt;ListView x:Name="ItemListView" ItemsSource="{Binding Source={StaticResource CollectionViewSource}}" ...
  </code></pre>