title: How do I replace Icon with rectangle In ContextMenu
body: <p>I have the need to replace the Icon in a MenuItem with a Rectangle. Currently I have this:</p>
  
  <pre><code>&lt;TextBox.ContextMenu&gt;
      &lt;ContextMenu Focusable="False" ItemsSource="{Binding Categories}"&gt;                           
          &lt;ContextMenu.ItemContainerStyle&gt;
              &lt;Style TargetType="{x:Type MenuItem}"&gt;
                  &lt;Setter Property="Header" Value="{Binding Name}"/&gt;
                  &lt;Setter Property="Focusable" Value="False"/&gt;         
              &lt;/Style&gt;         
          &lt;/ContextMenu.ItemContainerStyle&gt;
      &lt;/ContextMenu&gt;
  &lt;/TextBox.ContextMenu&gt;
  </code></pre>
  
  <p>Which works fine:</p>
  
  <p><img src="https://i.stack.imgur.com/RX0mj.png" alt="enter image description here"></p>
  
  <p>But I can't figure out how to edit the <em>MenuItem.Icon</em> and replace it with a rectangle.</p>
  
  <p>I've tried using a DataTemplate:</p>
  
  <pre><code>&lt;TextBox.ContextMenu&gt;
      &lt;ContextMenu Focusable="False" ItemsSource="{Binding Categories}"&gt;
          &lt;ContextMenu.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel Orientation="Horizontal" &gt;
                      &lt;Rectangle Width="20" Height="20" Fill="{Binding CategoryColor}"/&gt;
                      &lt;Label Content="{Binding Name}"/&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;ContextMenu.ItemTemplate&gt;
       &lt;/ContextMenu&gt;
  &lt;/TextBox.ContextMenu&gt;
  </code></pre>
  
  <p>And while this looks okay it would be nicer to get the Rectangle into the Icon area - or remove the icon area altogether. I also have to think about binding a Command to the MenuItem, if that makes a difference to the approach.</p>
  
  <p><img src="https://i.stack.imgur.com/Udzw6.png" alt="enter image description here"></p>
  
  <p>POSSIBLE SOLUTION:
  I've tried:</p>
  
  <pre><code>&lt;TextBox.ContextMenu&gt;
      &lt;ContextMenu Focusable="False" ItemsSource="{Binding Categories}"&gt;
          &lt;ContextMenu.Resources&gt;
              &lt;Rectangle x:Key="myRectangle" x:Shared="False" Width="20" Height="20" Fill="{Binding CategoryColor}"/&gt;
          &lt;/ContextMenu.Resources&gt;
          &lt;ContextMenu.ItemContainerStyle&gt;
              &lt;Style TargetType="{x:Type MenuItem}"&gt;
                  &lt;Setter Property="Header" Value="{Binding Name}"/&gt;
                  &lt;Setter Property="Focusable" Value="False"/&gt;  
                  &lt;Setter Property="Icon" Value="{StaticResource myRectangle}"/&gt;
              &lt;/Style&gt;         
          &lt;/ContextMenu.ItemContainerStyle&gt;
     &lt;/ContextMenu&gt;
  &lt;/TextBox.ContextMenu&gt;
  </code></pre>
  
  <p>But this only displays the last rectangle:</p>
  
  <p><img src="https://i.stack.imgur.com/0L1DY.png" alt="enter image description here"></p>