title: Hide the wpf context menu over the area where there is no rows in the wpf datagrid
body: <p>I have a WPF datagrid populated with datas. And I put a context menu on the row  items when right clicking on the  datarow. But the context menu is showing on the outside of datarow as  well. I hid the context menu on the column header as show below:</p>
  
  <pre><code>    &lt;Style x:Key="dgHeaderStyle" TargetType="dg:DataGridColumnHeader"&gt;
  
         &lt;Setter Property="ContextMenu"&gt;
             &lt;Setter.Value&gt;
                 &lt;ContextMenu Visibility="Collapsed" /&gt;
             &lt;/Setter.Value&gt;
         &lt;/Setter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p>But how to hide/collapsed the context menu on the outside of the datagrid row?</p>
  
  <p>I defined the context menu in the xaml as shown below:</p>
  
  <pre><code>    &lt;dg:DataGrid.ContextMenu&gt;
             &lt;ContextMenu&gt;
                  &lt;MenuItem Header="Update" Name="mnuUpdate" Click="mnuUpdate_Click" /&gt;
              &lt;/ContextMenu&gt;
          &lt;/dg:DataGrid.ContextMenu&gt;
  </code></pre>
  
  <p>I changed defining the context menu in grid.rowstyle. but it throws below shown error.</p>
  
  <p><a href="https://i.stack.imgur.com/AHUcK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AHUcK.png" alt="contextmenu"></a></p>