title: WPF DataGrid bound to an ObservableCollection that is updated on separate thread fails to maintain sort
body: <p><a href="http://cid-83a400d17a28233b.skydrive.live.com/redir.aspx?resid=83A400D17A28233B!123" rel="nofollow">Download Sample Project</a></p>
  
  <p>I have a wpf 4 datagrid that is bound to an ObservableCollection. This ObservableCollection is 
  updated on another thread. I can see the updates coming through to my simple gui just fine. I can even sort the data. But the sort does not "stick". It will sort once when you click the column header but when a value in the collection changes the sort does not change accordingly.</p>
  
  <p>The MainWindow backing code is where most of the action goes down (just for simplicity of the example). I create an ObservableCollection and pass it to a thread that does the actual writes to the ObservableCollection. I then bind that same ObservableCollection to the datagrid via a CollectionView (I've tried binding it directly as well). My hunch is that the sorting depends upon the collectionChanged event which I'm pretty sure won't fire back to the Dispatcher ( see: <a href="http://bea.stollnitz.com/blog/?p=34" rel="nofollow">http://bea.stollnitz.com/blog/?p=34</a>). </p>
  
  <p>What to do?</p>
  
  <pre><code>    public partial class MainWindow : Window
  {
      private Thread _dataThread;
      private Thread _marketThread;
      private SampleData _sampleData;
      private Market _market;
      private ObservableCollection&lt;Stock&gt; stocks;
      private ConcurrentQueue&lt;Stock&gt; _updates = new ConcurrentQueue&lt;Stock&gt;();
      public MainWindow()
      {
          InitializeComponent();
  
          stocks = new ObservableCollection&lt;Stock&gt;();
  
          for (var i = 0; i &lt; 5; i++)
          {
              var newStock = new Stock();
              newStock.Id = (uint)i;
              stocks.Add(newStock);
          }
  
          var source = CollectionViewSource.GetDefaultView(stocks);
  
          dataGrid.ItemsSource = source;
          _sampleData = new SampleData(_updates);
          _dataThread = new Thread(_sampleData.CreateData) { Name = "Data Thread" };
          _dataThread.Start();
  
          _market = new Market(_updates, stocks);
          _marketThread = new Thread(_market.Start){Name = "Market Thread"};
          _marketThread.Start();
  
      }
  
  }
  </code></pre>
  
  <p>Challenge.</p>
  
  <p><a href="http://cid-83a400d17a28233b.skydrive.live.com/redir.aspx?resid=83A400D17A28233B!123" rel="nofollow">Download Sample Project</a></p>