title: Making a custom DataGrid
body: <p>I would like to create a custom WPF DataGrid that includes a custom context menu as well as some custom key bindings. It needs to be some kind of custom control since we will have many instances of the same datagrid.</p>
  
  <p>So far I have the following:</p>
  
  <pre><code>public class MyDataGrid : DataGrid
  {
      static MyDataGrid()
      {
          DefaultStyleKeyProperty.OverrideMetadata(typeof(MyDataGrid), new FrameworkPropertyMetadata(typeof(MyDataGrid)));
      }
  }
  </code></pre>
  
  <p>And in the Themes folder, I have MyDataGrid.xaml which contains:</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  
      &lt;Style TargetType="{x:Type DataGrid}"&gt;
          &lt;Setter Property="ContextMenu"&gt;
              &lt;Setter.Value&gt;
                  &lt;ContextMenu&gt;
                      &lt;MenuItem Header="Copy" Command="{Binding CopyCommand}" /&gt;
                      &lt;MenuItem Header="Paste" Command="{Binding PasteCommand }" /&gt;
                      &lt;Separator /&gt;
                      &lt;MenuItem Header="Insert" Command="{Binding InsertCommand }" /&gt;
                      &lt;MenuItem Header="Delete" Command="{Binding DeleteCommand }" /&gt;
                      &lt;Separator /&gt;
                      &lt;MenuItem Header="Move Up" Command="{Binding MoveUpCommand }" /&gt;
                      &lt;MenuItem Header="Move Down" Command="{Binding MoveDownCommand }" /&gt;
                  &lt;/ContextMenu&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>However, when I create an instance of my control, it's just blank.</p>
  
  <pre><code>&lt;custom:MyDataGrid
      ItemsSource ="{Binding MyObjects}" 
      SelectedItem="{Binding SelectedObject}"
      AutoGenerateColumns="False"
      CanUserResizeColumns="True"  
      ClipboardCopyMode="ExcludeHeader" 
      CanUserResizeRows="False"
      CanUserSortColumns="False"     
      SelectionMode="Extended"
      EnableRowVirtualization="False"&gt;
  
      ...
  
  &lt;/custom:MyDataGrid&gt;
  </code></pre>
  
  <p>What am I doing wrong? This is the first time I've tried to create a custom control.</p>