title: WPF DataGrid ignores SortDescription
body: <p>I've got a strange problem here regarding sorting of a WPF DataGrid (System.Windows.Controls.DataGrid in .NET 4.0). </p>
  
  <p>Its ItemsSource is bound to a property of the datacontext object:</p>
  
  <pre><code>&lt;DataGrid HeadersVisibility="Column" SelectedIndex="0" MinHeight="30" ItemsSource="{Binding FahrtenView}" AutoGenerateColumns="False" x:Name="fahrtenDG"&gt;
  </code></pre>
  
  <p>FahrtenView looks like this:</p>
  
  <pre><code>    public ICollectionView FahrtenView
      {
          get
          {
              var view = CollectionViewSource.GetDefaultView(_fahrten);
              view.SortDescriptions.Add(new SortDescription("Index", ListSortDirection.Ascending));
              return view;
          }
      }
  </code></pre>
  
  <p>The DataGrid gets sorted. However it only gets sorted the very first time it's assigned a DataContext. After that, changing the DataContext (by selecting another "parental" object in a data hierarchy) still causes the property FahrtenView to be evaluated (I can put a BP in and debugger stops there) but the added sortdescription is completely ignored, hence sorting does not work anymore. </p>
  
  <p>Even calling fahrtenDG.Items.Refresh() on every DataContextChange doesn't help. </p>
  
  <p>I'm pretty sure this is the way to go when it comes to sorting a WPF DataGrid, isn't it? So why does it refuse to work so obstinately after doing its job perfectly the very first time it gets called?</p>
  
  <p>Any idea? I'd be very grateful.</p>
  
  <p>Cheers,
  Hendrik</p>