title: How can I get a DataGrid to unselect on click when SelectionMode="Extended"?
body: <p>The default behaviour of a WPF <code>DataGrid</code> is to select when a row is clicked if <code>SelectionMode="Extended"</code> which is what I want, however I also wish for the row to un-select if it was previously already selected when clicked.</p>
  
  <p>I have tried the following which will unselect the row as soon as it's selected, it seems the row selection occurs before the mouse click event.</p>
  
  <pre><code>private void DoGridMouseLeftButtonUp(object sender, MouseButtonEventArgs args) {
      // Get source row.
      DependencyObject source = (DependencyObject)args.OriginalSource;
      var row = source.FindParent&lt;DataGridRow&gt;();
      if (row == null)
          return;
      // If selected, unselect.
      if (row.IsSelected) {
          row.IsSelected = false;
          args.Handled = true;
      }
  }
  </code></pre>
  
  <p>Where I am binding to this event with the following grid.</p>
  
  <pre><code>&lt;DataGrid SelectionMode="Extended"
            SelectionUnit="FullRow"
            MouseLeftButtonUp="DoGridMouseLeftButtonUp"&gt;
  </code></pre>