title: ShowDialog in WPF throwing not agree with the current state
body: <p>I keep getting the following error when i open a <code>SaveFileDialog</code> in WPF, but i must be honest and say that the error dose not make much sense to me.</p>
  
  <p>Information for developers:</p>
  
  <blockquote>
    <p>This exception was thrown because the generator for control 'System.Windows.Controls.ListBox Items.Count:4' with name '(unnamed)' has received sequence of CollectionChanged events that do not agree with the current state of the Items collection.  The following differences were detected:
      Accumulated count 2 is different from actual count 4.  [Accumulated count is (Count at last Reset + #Adds - #Removes since last Reset).]</p>
    
    <p>One or more of the following sources may have raised the wrong events:
         System.Windows.Controls.ItemContainerGenerator
          System.Windows.Controls.ItemCollection
           System.Windows.Data.ListCollectionView
      *     XmlDiff.Gui.ViewModels.MTObservableCollection`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
    (The starred sources are considered more likely to be the cause of the problem.)</p>
    
    <p>The most common causes are (a) changing the collection or its Count without raising a corresponding event, and (b) raising an event with an incorrect index or item parameter.</p>
    
    <p>The exception's stack trace describes how the inconsistencies were detected, not how they occurred.  To get a more timely exception, set the attached property 'PresentationTraceSources.TraceLevel' on the generator to value 'High' and rerun the scenario.  One way to do this is to run a command similar to the following:
       System.Diagnostics.PresentationTraceSources.SetTraceLevel(myItemsControl.ItemContainerGenerator, System.Diagnostics.PresentationTraceLevel.High)
    from the Immediate window.  This causes the detection logic to run after every CollectionChanged event, so it will slow down the application.</p>
  </blockquote>
  
  <p>The error occur when i run the following method. It dose not run on the GUI thread, but should that matter when i create a new SaveFileDialog.</p>
  
  <pre><code>private string ShowSaveFileDialog(string defaultName)
  {
      Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog
      {
          FileName = defaultName,
          DefaultExt = ".xml",
          Filter = "Xml documents (.xml)|*.xml"
      };
  
      // Show open file dialog box 
      Nullable&lt;bool&gt; result = dlg.ShowDialog();
  
      // Process open file dialog box results 
      if (result == true)
          return dlg.FileName;
      return null;
  }
  </code></pre>