title: MVVM WPF DataGrid SelectedItem via binding fires OnPropertyChanged twice
body: <p>I've spent quite a few hours trying to solve the problem described below:</p>
  
  <p>I've got a DataGrid defined in my MVVM WPF application, the stripped down XAML code looks like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;DataGrid AutoGenerateColumns="False" Name="dgdSomeDataGrid" SelectedItem="{Binding SelectedSomeItem, Mode=TwoWay}" ItemsSource="{Binding SomeItemCollection}"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=Id}" Header="ID" /&gt;
          &lt;DataGridTextColumn Header="Titel" Binding="{Binding Path=Title}" /&gt;
          &lt;DataGridTextColumn Header="Status" Binding="{Binding Path=State}" /&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>In my associated ViewModel I've got a corresponding property like:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public WorkItemForUi SelectedSomeItem
  {
      get
      {
          return SomeObject.SelectedSomeItem;
      }
      set
      {
          SomeObject.SelectedSomeItem = value;
          OnPropertyChanged( "SelectedSomeItem" );
      }
  }
  </code></pre>
  
  <p>In my controller I've got the following:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void MainWindowViewModelPropertyChanged( object sender, PropertyChangedEventArgs e )
  {
      if ( e.PropertyName == "SelectedSomeItem" )
      {
          UpdateSelectedSomeItem();
      }
  }
  </code></pre>
  
  <p>What I generally want to do is to retrieve the selected item from the <code>DataGrid</code>, get some more information about the item from an external data store (a TFS in this case) and show that extra information in a TextBox. </p>
  
  <p>All of this already works as expected, but <strong>the problem is that the MainWindowViewModelPropertyChanged method is called twice, not once</strong>.</p>
  
  <p>It may be the case that it is by design for the <code>SelectedItem</code> property being set to happen twice, but I'm not quite sure as a lot of information I found is a bit contradictory (and also sometimes not quite clear whether Windows Forms or WPF are meant).</p>
  
  <p>I've seen some suggestions where a SelectionChanged event handler is defined for the <code>DataGrid</code> and an <code>IsSelected</code> property is used, but as far as I know this shouldn't be necessary due to my data binding.</p>
  
  <p><strong>Update</strong>
  As part of the MainWindowController there is an Initialize method that references the MainWindowViewModelPropertyChanged handler.</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public void Initialize( string tfsProjectCollection )
      {
          InitializeCommands();
          InitializeViewModel();
          AddWeakEventListener( m_MainWindowViewModel, MainWindowViewModelPropertyChanged );
      }
  </code></pre>
  
  <p>Any ideas what might be the cause of my problem?</p>