title: WPF MenuItem.Command binding to ElementName results to System.Windows.Data Error: 4 : Cannot find source for binding with reference
body: <p>I have the following XAML:</p>
  
  <pre><code>&lt;UserControl x:Class="EMS.Controls.Dictionary.TOCControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:vm="clr-namespace:EMS.Controls.Dictionary.Models"
      xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
      x:Name="root"  &gt;
  
      &lt;TreeView                    
          x:Name="TOCTreeView"                    
          Background="White"
           Padding="3,5"      
          ContextMenuOpening="TOCTreeView_ContextMenuOpening"
          ItemsSource="{Binding Children}" BorderBrush="{x:Null}"  &gt;
  
          &lt;TreeView.ItemTemplate&gt;
              &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"&gt;
                  &lt;Grid &gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;!--&lt;ColumnDefinition Width="Auto"/&gt;--&gt;                       
                          &lt;ColumnDefinition Width="*"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;!--&lt;CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/&gt;--&gt;   
                      &lt;ContentPresenter Grid.Column="0" Height="16" Width="20"
                                      Content="{Binding LayerRepresentation}"  /&gt;
                      &lt;!--&lt;ContentPresenter Grid.Column="1"      &gt;
                          &lt;ContentPresenter.Content&gt;
                              Test
                          &lt;/ContentPresenter.Content&gt;
                      &lt;/ContentPresenter&gt;--&gt;
                      &lt;TextBlock Grid.Column="2" FontWeight="Normal" Text="{Binding Path=Alias, Mode=OneWay}" &gt;
                          &lt;ToolTipService.ToolTip&gt;
                              &lt;TextBlock Text="{Binding Description}" TextWrapping="Wrap"/&gt;
                          &lt;/ToolTipService.ToolTip&gt;
                      &lt;/TextBlock&gt;
                  &lt;/Grid&gt;
                  &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                      &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"&gt;
                          &lt;!--&lt;DataTemplate&gt;--&gt;
                          &lt;Grid &gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;                               
                                  &lt;ColumnDefinition Width="*"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                              &lt;CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/&gt;
                              &lt;ContentPresenter Grid.Column="1"
                                      Content="{Binding LayerRepresentation, Mode=OneWay}"  /&gt;
                              &lt;TextBlock Margin="0,1,0,1" Text="{Binding Path=Alias, Mode=OneWay}" Grid.Column="2"&gt;
                                  &lt;ToolTipService.ToolTip&gt;
                                      &lt;TextBlock Text="{Binding Description}" TextWrapping="Wrap"/&gt;
                                  &lt;/ToolTipService.ToolTip&gt;                   
                              &lt;/TextBlock&gt;
                          &lt;/Grid&gt;
                          &lt;!--&lt;/DataTemplate&gt;--&gt;
                      &lt;/HierarchicalDataTemplate&gt;                  
                  &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/TreeView.ItemTemplate&gt; 
  
          &lt;TreeView.ContextMenu&gt;
              &lt;ContextMenu&gt;
                  &lt;MenuItem Name="miRemove" Header="Remove"
                            Command="{Binding ElementName=root, Path=RemoveItemCmd, 
                      diagnostics:PresentationTraceSources.TraceLevel=High}"&gt;
                      &lt;MenuItem.Icon&gt;
                          &lt;Image Source="../images/16x16/Delete.png"/&gt;
                      &lt;/MenuItem.Icon&gt;
                  &lt;/MenuItem&gt;
                  &lt;MenuItem Header="Properties"
                            Command="{Binding ElementName=root, Path=GetItemPropertiesCmd}"/&gt;               
              &lt;/ContextMenu&gt;       
          &lt;/TreeView.ContextMenu&gt;
  
  
      &lt;/TreeView&gt;
  
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Code behind for this UserControl has two ICommand properties with names: RemoveItemCmd and GetItemPropertiesCmd.  However, I get </p>
  
  <blockquote>
  <pre>
  System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=RemoveItemCmd; DataItem=null; target element is 'MenuItem' (Name='miRemove'); target property is 'Command' (type 'ICommand')
  System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=GetItemPropertiesCmd; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand')
  </pre>
  </blockquote>
  
  <p>when UserControl is constructed. Why is this and how do I resolve?</p>