title: WPF DataGrid binding doesn't update
body: <p>Here's my <code>DataGrid</code>:</p>
  
  <pre><code>&lt;DataGrid x:Name="MoonMining" 
            ItemsSource="{Binding MarketData.MoonMinerals, ElementName=window}"&gt;
      &lt;DataGrid.DataContext&gt;
          &lt;local:MoonMineral/&gt;
      &lt;/DataGrid.DataContext&gt;
      &lt;DataGrid.Columns&gt;
          .. Yes i have columns and they are irrelevant to my question .
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p><code>MarketData</code> is a class which contains most of my programs logic. <code>MoonMinerals</code> is defined in that class:</p>
  
  <pre><code>public class MarketData
  {
     private ObservableCollection&lt;MoonMineral&gt; _moonMinerals = new ObservableCollection&lt;MoonMineral&gt;();
  
     public ObservableCollection&lt;MoonMineral&gt; MoonMinerals
     {
         get { return _moonMinerals; }
         set { _moonMinerals = value; }
     }
   }
  </code></pre>
  
  <p>And here's my <code>MoonMineral</code> class:</p>
  
  <pre><code>[NotifyPropertyChanged]
  public class MoonMineral
  {
      public MoonMineral()
          : this("Def", "Def")
      {
      }
  
      public MoonMineral(string name, string rarity)
      {
          Name = name;
          Rarity = rarity;
      }
  
      public string Name { get; set; }
      public double Price { get; set; }
      public double Volume { get; set; }
      public string Rarity { get; set; }
      public double TransportVolume { get; set; }
      public double TransportCosts { get; set; }
      public double GrossProfit { get; set; }
      public double NetProfit { get; set; }
  }
  </code></pre>
  
  <p>As you can see, I'm using PostSharp to clear up my code, but when I manually implement <code>INotifyPropertyChanged</code> I have the same problem.</p>
  
  <p>Now the problem is that my <code>DataGrid</code> doesn't update by itself, I have to manually call this in a method which modifies <code>MoonMinerals</code>:</p>
  
  <pre><code>var bindingExpression = MoonMining.GetBindingExpression(ItemsControl.ItemsSourceProperty);
  if (bindingExpression != null)
      bindingExpression.UpdateTarget();
  </code></pre>
  
  <p>I know this isn't big of a deal, but I wanted to finally manage to bind data to ui entirely using xaml. All my previous attempts involved setting <code>DataGrids</code> <code>ItemsSource</code> property every time I updated the data.</p>