title: How to set an Icon in a ContextMenu's MenuItem when using ItemContainerStyle
body: <p>So I have a <code>Context Menu</code> And a <code>MenuItem</code> in it which breaks out into a list of names:</p>
  
  <pre><code>&lt;ContextMenu&gt;
      &lt;MenuItem Header="Set As Default For" ItemsSource="{Binding Source={StaticResource Names}}"&gt;
         &lt;MenuItem.ItemContainerStyle&gt;
             &lt;Style TargetType="MenuItem"&gt;
                  &lt;Setter Property="Header" Value={Binding Name}/&gt;
                  &lt;Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.DoSomething}" /&gt;
                  &lt;Setter Property="CommandParameter" Value="{Binding }" /&gt;
              &lt;/Style&gt;
           &lt;/MenuItem.ItemContainerStyle&gt;
       &lt;/MenuItem&gt;
  &lt;/ContextMenu&gt;
  </code></pre>
  
  <p>Now the above code works file and displays my list of names. Now I would like to add an Icon next to each Name using a Pack URI.. So from <a href="https://stackoverflow.com/questions/1763763/wpf-menu-item-with-image">this question</a> I can see the best way to do it is to template the <code>Header</code> so I tried that first like the question</p>
  
  <pre><code>&lt;ContextMenu&gt;
      &lt;MenuItem Header="Set As Default For" ItemsSource="{Binding Source={StaticResource Names}}"&gt;
         &lt;MenuItem.ItemContainerStyle&gt;
             &lt;Style TargetType="MenuItem"&gt;
                  &lt;Setter Property="Header"&gt;
                      &lt;Setter.Value&gt;
                           &lt;StackPanel&gt;
                                 &lt;Image Width="20" Height="20" Source="/MyProj;component/Resources/MyImg.png" /&gt;
                                &lt;ContentPresenter Content="{Binding Name}" /&gt;
                            &lt;/StackPanel&gt;
                       &lt;/Setter.Value&gt;
                   &lt;/Setter&gt;
                   &lt;Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.DoSomething}" /&gt;
                   &lt;Setter Property="CommandParameter" Value="{Binding }" /&gt;
              &lt;/Style&gt;
           &lt;/MenuItem.ItemContainerStyle&gt;
       &lt;/MenuItem&gt;
  &lt;/ContextMenu&gt;
  </code></pre>
  
  <p>but this gave me the error: </p>
  
  <blockquote>
    <p>Specified element is already the logical child of another element.
    Disconnect it first.</p>
  </blockquote>
  
  <p>So I after some research I tried:</p>
  
  <pre><code>&lt;ContextMenu&gt;
      &lt;MenuItem Header="Set As Default For" ItemsSource="{Binding Source={StaticResource Names}}"&gt;
         &lt;MenuItem.ItemContainerStyle&gt;
             &lt;Style TargetType="MenuItem"&gt;
                  &lt;Setter Property="Header"&gt;
                      &lt;Setter.Value&gt;
                           &lt;ControlTemplate&gt;
                               &lt;StackPanel&gt;
                                     &lt;Image Width="20" Height="20" Source="/MyProj;component/Resources/MyImg.png" /&gt;
                                      &lt;ContentPresenter Content="{Binding Name}" /&gt;
                                &lt;/StackPanel&gt;
                             &lt;/ControlTemplate&gt;
                       &lt;/Setter.Value&gt;
                   &lt;/Setter&gt;
                   &lt;Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.DoSomething}" /&gt;
                   &lt;Setter Property="CommandParameter" Value="{Binding }" /&gt;
              &lt;/Style&gt;
           &lt;/MenuItem.ItemContainerStyle&gt;
       &lt;/MenuItem&gt;
  &lt;/ContextMenu&gt;
  </code></pre>
  
  <p>But now all my names are ControlTemplate and no icon is displayed...</p>
  
  <p>How do I add an icon to a Context Menu's Menu Item through ItemContainerStyle?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've tried:</p>
  
  <pre><code>   &lt;Setter Property="Header" Value="{Binding Name}"/&gt;
     &lt;Setter Property="Icon"&gt;
         &lt;Setter.Value&gt;
             &lt;Image Width="20" Height="20" Source="/MyProj;component/Resources/MyImg.png" /&gt;
         &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  </code></pre>
  
  <p>And I get an icon rendering but only for the last item in my menu?</p>