title: Binding command to a MenuItem using HierarchicalDataTemplate
body: <p>I currently have a treeview that displays data using a hierarchicaldatatemplate and when the user clicks on the Remove button, it removes the selected node(s).  This works as intended.</p>
  
  <p>However, Instead of having the user click a button I'm trying to have the command be executed by right clicking a node and selecting the appropriate menu item.</p>
  
  <p>This is proving to be much more difficult because it is being picked up by the ViewModel of a node (which doesn't know anything about the View) instead of the View's corresponding ViewModel.</p>
  
  <p>Is there someway to hand the control over to the ViewModel of the View instead?</p>
  
  <p>Here is the code for the Remove Button:</p>
  
  <p>View:</p>
  
  <pre><code>        &lt;Button Content="Remove" Grid.Row="2" Height="23" VerticalAlignment="Top" Name="removeButton" 
                  Width="75"  Margin="5,20,5,0"  Command="{Binding Path=RemoveCommand}" /&gt;
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public RelayCommand RemoveCommand
          {
              get
              {
                  if (_removeCommand == null)
                  {
                      _removeCommand = new RelayCommand(
                          () =&gt; this.Remove()
                          );
                  }
                  return _removeCommand;
              }
          }
  
          public void Remove()
          {
              _organLocationTree2.RemoveOrganLocations(ProjectOrganLocationView.GetExtendedTreeView().SelectedItems);
              ProjectOrganLocationView.GetExtendedTreeView().SelectedItems.Clear();
  
              base.RaisePropertyChanged("DestOrganTree");
          }
  </code></pre>
  
  <p>And the XAML for the menu item:</p>
  
  <pre><code>            &lt;local:ExtendedTreeView.ItemTemplate&gt;
                  &lt;HierarchicalDataTemplate ItemsSource="{Binding SubOrganLocations}"&gt;
                      &lt;TextBlock Text="{Binding OrganName}" &gt;
              &lt;TextBlock.ContextMenu&gt;
                  &lt;ContextMenu&gt;
                      &lt;MenuItem Header ="Add SubNode" Command="{Binding Path=MenuItem_Add}"&gt;&lt;/MenuItem&gt;
                      &lt;MenuItem Header ="Remove Node" Command="{Binding Path=RemoveCommand}"&gt;&lt;/MenuItem&gt;
                      &lt;MenuItem Header ="Edit Node" Command="{Binding Path=ProjMenuItem_Edit}"
                                CommandParameter="{Binding DestOrganTree, Path=Selected.OrganName}"&gt;&lt;/MenuItem&gt;
                  &lt;/ContextMenu&gt;
              &lt;/TextBlock.ContextMenu&gt;
                      &lt;/TextBlock&gt;
                  &lt;/HierarchicalDataTemplate&gt;
              &lt;/local:ExtendedTreeView.ItemTemplate&gt;
          &lt;/local:ExtendedTreeView&gt;
  </code></pre>
  
  <p>I tried to implement a Remove command in the ViewModel of the node, but since it doesn't know anything about the View it got very messy very quickly.</p>