title: Datagrid context menu only for single select
body: <p>I have a datagrid with context menu. How prevent context menu showing for multiple selection? I tried to add attached property but got an error <strong>The attachable property 'ContextMenuVisibilityMode' was not found in type 'ProcessIntasnceActivitiesView'</strong></p>
  
  <pre><code>namespace TiM.Windows.App.View
  {
  public partial class ProcessIntasnceActivitiesView
  {
  public static readonly DependencyProperty ContextMenuVisibilityModeProperty =
    DependencyProperty.RegisterAttached("ContextMenuVisibilityMode", typeof (string),
      typeof (ProcessIntasnceActivitiesView),
      new PropertyMetadata("Multiple", OnContextMenuVisibilityModeChanged));
  
  private static void OnContextMenuVisibilityModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
    var dgrd = d as DataGrid;
  
    if (dgrd != null)
      dgrd.ContextMenuOpening += (sender, args) =&gt;
      {
        switch (e.NewValue.ToString())
        {
          case "Single":
            args.Handled = (sender as DataGrid)?.SelectedItems.Count &gt; 1;
            break;
          case "Multiple":
            args.Handled = !((sender as DataGrid)?.SelectedItems.Count &gt; 1);
            break;
        }
      };
    }
   ...
  
  }
  
  xmlns:local="clr-namespace:TiM.Windows.App.View"
  &lt;DataGrid ... local:ProcessIntasnceActivitiesView.ContextMenuVisibilityMode="Single"&gt;
  </code></pre>