title: Disable the row selection on right click in wpf datagrid if row is already selected
body: <p>I am working on a datagrid which enable user to select multiple rows. but when user clicks on header of row the selection get lost.</p>
  
  <p>How can I disable the row selection on right click if the row is already selected.</p>
  
  <p>I tried to do it via Behavior</p>
  
  <pre><code>public class DataGridRowBehavior
  {
  
      public static readonly DependencyProperty DisableSelectionOnRightClickProperty = DependencyProperty.RegisterAttached(
                  "DisableSelectionOnRightClick",
                  typeof(bool),
                  typeof(DataGridRowBehavior),
                  new UIPropertyMetadata(false, OnDisableSelectionOnRightClick));
  
  
      public static bool GetDisableSelectionOnRightClick(DependencyObject dgRow)
      {
          return (bool)dgRow.GetValue(DisableSelectionOnRightClickProperty);
      }
  
      public static void SetDisableSelectionOnRightClick(DependencyObject dgRow, bool value)
      {
          dgRow.SetValue(DisableSelectionOnRightClickProperty, value);
      }
  
      public static void SetListViewFocus(DependencyObject d, bool use)
      {
          d.SetValue(DisableSelectionOnRightClickProperty, use);
      }
  
      public static void OnDisableSelectionOnRightClick(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          DataGridRowHeader header = d as DataGridRowHeader;
          header.MouseRightButtonUp += header_MouseRightButtonUp;
      }
  
      static void header_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
      {
          var header = sender as DataGridRowHeader;
  
          if (header.IsRowSelected)
          {
              if (header.ContextMenu != null)
              {
                  header.ContextMenu.IsOpen = true;
              }
  
              e.Handled = true;
          }
      }
  }
  </code></pre>
  
  <p>But this one is not working correctly as other functionality of right click is also broken. e.g Context menu. The context menu is not enabling its Application Commands.</p>
  
  <p>Is there any other way to disable the selection or let the selection remain as it is if I click on any of the selected row?</p>