title: WPF + Binding Command and Header of a Context Menu Item using MVVM
body: <p>I created a WPF application and am following MVVM Pattern.  I have a context menu in my xaml and I need to bind the command and Header text.  Using the following code I can bind the Header of the context menu with the "MenuItemName" which is a property in BOList which is an observable collection.  My issue is that command is not getting fired?  I changes the Item source of the Context Menu to datacontext </p>
  
  <pre><code>(DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}") 
  </code></pre>
  
  <p>Command is working fine but my header is getting blank. Is there a way to bind my header and command of a menu item?  Here the command MenuClick is a Icommand property in the VM and MenuItemName is a property inside BOList which is an observable collection binded to my ListBox.</p>
  
  <pre><code>&lt;Grid&gt;
  &lt;StackPanel Orientation="Vertical"&gt;
     &lt;Button x:Name="btnClickMe" Command="{Binding ButtonCommand}" Content="Click Me" /&gt;
    &lt;ListBox ItemsSource="{Binding BOList}" x:Name="lstDemo" SelectedItem="{Binding BussinessObj,Mode=OneWayToSource}"&gt;
      &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
          &lt;StackPanel x:Name="stkStyleRender" Orientation="Horizontal" Background="Cyan" Width="525"  Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" &gt;
            &lt;TextBlock x:Name="txtId" Text="{Binding FirstName}"&gt;&lt;/TextBlock&gt;
            &lt;TextBlock x:Name="txtName" Text="{Binding LastName}"&gt;&lt;/TextBlock&gt;
            &lt;StackPanel.ContextMenu&gt;
              &lt;ContextMenu x:Name="cntMnuTest" ItemsSource ="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}" &gt;
                &lt;MenuItem Header="{Binding MenuItemName}"  Command="{Binding MenuClick}" CommandParameter="Icon"&gt;&lt;/MenuItem&gt;
              &lt;/ContextMenu&gt; 
            &lt;/StackPanel.ContextMenu&gt;
  
          &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
   &lt;/ListBox&gt;
  &lt;/StackPanel&gt; 
  </code></pre>
  
  <p></p>