Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to use <code>ItemContainerStyle</code> instead of <code>DataTemplate</code>. You have to style the container of the data item than just providing a template for data item.</p> <p>With your <code>DataTemplate</code>, you basically displaying another nested MenuItem as content for each MenuItem generated for your Menu <em>Something</em>, and your inner MenuItem has the image in the correct place. I am attaching VisualTree from Snoop here for your reference.</p> <p><img src="https://i.stack.imgur.com/6MeqK.png" alt="Nested MenuItems"></p> <p>Below is the Style for the container of the data item (in this case a <code>MenuItem</code>):</p> <pre><code>&lt;MenuItem ItemsSource="{Binding SomethingMenuItems}" Header="Something"&gt; &lt;MenuItem.Resources&gt; &lt;Image Source="{Binding IconPath}" x:Key="IconImage" x:Shared="False"/&gt; &lt;Style TargetType="MenuItem" &gt; &lt;Setter Property="Header" Value="{Binding Name}" /&gt; &lt;Setter Property="Icon" Value="{StaticResource IconImage}" /&gt; &lt;/Style&gt; &lt;/MenuItem.Resources&gt; &lt;/MenuItem&gt; </code></pre> <p>You can see no nested MenuItems when you apply the above style, have added image here <img src="https://i.stack.imgur.com/5zULO.png" alt="No Nested MenuItems"></p> <p>With the above style applied, this is how the Menu looks:</p> <p><img src="https://i.stack.imgur.com/ufOIa.png" alt="Menu after Container Style"></p> <p>Refer to <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainerstyle.aspx" rel="nofollow noreferrer">this</a> MSDN page to know more about <code>ItemContainerStyle</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload