WPF menu item with image

WpfImageMenuMenuitem

Wpf Problem Overview


How to define MenuItem.Icon so that the MenuItemHeader text would be placed below the menu item image?Thanks for help!

Wpf Solutions


Solution 1 - Wpf

How something along the lines of:

<ContextMenu>
    <MenuItem Header="Reports">
        <MenuItem.Icon>
            <Image Source="/XSoftArt.WPFengine;component/Images/export32x32xp.png"/>
        </MenuItem.Icon>
    </MenuItem>
</ContextMenu>

Solution 2 - Wpf

The easy way way is to not use the Icon property but to instead put the icon in the Header:

<Menu>
  <MenuItem>
    <MenuItem.Header>
      <StackPanel>
        <Image Width="20" Height="20" Source="/XSoftArt.WPFengine;component/Images/export32x32xp.png" />
        <ContentPresenter Content="Reports" />
      </StackPanel>
    </MenuItem.Header>
  </MenuItem>
  <MenuItem Header="Export" />
  <MenuItem Header="New record" />
</Menu>

For this simple case the <ContentPresenter Content="Reports" /> can be replaced with a <TextBlock Text="Reports" /> because that's what ContentPresenter would use to present the string anyway. For more complex Header=, you could use the ContentPresenter as shown.

Solution 3 - Wpf

In the case of StackPanel use Label and not the TextBlock since only Label will allow you to have the mnemonics on the menu, like _Reports.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVytasView Question on Stackoverflow
Solution 1 - WpfDanielEView Answer on Stackoverflow
Solution 2 - WpfRay BurnsView Answer on Stackoverflow
Solution 3 - WpftridyView Answer on Stackoverflow