title: Silverlight DataGrid: Toolkit ContextMenu over entire Row
body: <p>I'm developing a Silverlight 4 application and want to achieve a seemingly easy task:
  I have this DataGrid:</p>
  
  <pre><code>&lt;sdk:DataGrid x:Name="dg" Grid.Row="1"  Grid.ColumnSpan="2" Width="800" ItemsSource="{Binding SearchResults}" AutoGenerateColumns="False" &gt;
                      &lt;sdk:DataGrid.Columns&gt;
                          &lt;sdk:DataGridTemplateColumn SortMemberPath="Name" Header="Name" CellTemplate="{StaticResource SearchGridNameFieldtemplate}"&gt;
  
                          &lt;/sdk:DataGridTemplateColumn&gt;
                          &lt;sdk:DataGridTemplateColumn SortMemberPath="samAccountName" Header="Kontoname" CellTemplate="{StaticResource SearchGridAccountNameFieldtemplate}"&gt;
  
                          &lt;/sdk:DataGridTemplateColumn&gt;
  
                          &lt;sdk:DataGridTextColumn Header="Description" 
              Binding="{Binding Principal.Description}" /&gt;
                          &lt;sdk:DataGridTextColumn Header="Container" 
              Binding="{Binding Principal.ContainerDN}" /&gt;
  
                      &lt;/sdk:DataGrid.Columns&gt;
                  &lt;/sdk:DataGrid&gt;
  </code></pre>
  
  <p>Now I am using a DataTemplate for the TemplateColumn which uses a toolkit Contextmenu like this</p>
  
  <pre><code>&lt;DataTemplate x:Key="DirectoryUserSearchItemViewModel"  &gt;
                                      &lt;StackPanel Orientation="Horizontal"&gt;
                                          &lt;controlsInputToolkit:ContextMenuService.ContextMenu&gt;
                                              &lt;controlsInputToolkit:ContextMenu&gt;
                                                  &lt;controlsInputToolkit:MenuItem Header="Eigenschaften" Command="{Binding EditItem}" Visibility="{Binding User.DistinguishedName, Converter={StaticResource UserPermissionVisibilityConverter},ConverterParameter=1;8}" CommandParameter="{Binding User}"&gt;
                                                      &lt;controlsInputToolkit:MenuItem.Icon&gt;
                                                          &lt;Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/&gt;
                                                      &lt;/controlsInputToolkit:MenuItem.Icon&gt;
                                                  &lt;/controlsInputToolkit:MenuItem&gt;
                                                  &lt;controlsInputToolkit:MenuItem Header="User endgültig löschen" Command="{Binding HardDeleteAccount}" Visibility="{Binding HardDeleteCommandVisibility}" CommandParameter="{Binding User}"&gt;
                                                      &lt;controlsInputToolkit:MenuItem.Icon&gt;
                                                          &lt;Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/&gt;
                                                      &lt;/controlsInputToolkit:MenuItem.Icon&gt;
                                                  &lt;/controlsInputToolkit:MenuItem&gt;
                                                  &lt;controlsInputToolkit:MenuItem Header="Externe Anwendung ausführen" Command="{Binding ExecuteExternalApplication}" CommandParameter="{Binding User}"&gt;
                                                      &lt;controlsInputToolkit:MenuItem.Icon&gt;
                                                          &lt;Rectangle Width="16" Height="16" Fill="{StaticResource MoveUpBrush}"/&gt;
                                                      &lt;/controlsInputToolkit:MenuItem.Icon&gt;
                                                  &lt;/controlsInputToolkit:MenuItem&gt;
                                              &lt;/controlsInputToolkit:ContextMenu&gt;
                                          &lt;/controlsInputToolkit:ContextMenuService.ContextMenu&gt;
                                          &lt;TextBlock Text="{Binding Principal.Name}"/&gt;
                                      &lt;/StackPanel&gt;
                                  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Here's the fun part: Do I really have to copy paste the whole context menu datatemplate FOR EACH column in my grid if I want to be able to right click anywhere in a row and activate the context menu? Can't I set this for an entire row? Other posts on stackoverflow didnt seem to give an answer to this specific problem.</p>