WPF menu item with image

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

+44
image wpf menuitem menu
Nov 19 '09 at 14:42
source share
3 answers

The easiest way is not to use the Icon property, but 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> 

In this simple case, <ContentPresenter Content="Reports" /> can be replaced with <TextBlock Text="Reports" /> , because what ContentPresenter will use to represent the string anyway. For more complex Header= you can use ContentPresenter as shown.

+44
Nov 19 '09 at 14:48
source share
— -

Like something like:

 <ContextMenu> <MenuItem Header="Reports"> <MenuItem.Icon> <Image Source="/XSoftArt.WPFengine;component/Images/export32x32xp.png"/> </MenuItem.Icon> </MenuItem> </ContextMenu> 
+98
Jun 02 '10 at 16:34
source share

In the case of the StackPanel, use a Label, not a TextBlock, since only a Label will allow you to have mnemonics in the menu, for example _Reports.

+2
Jul 28 '10 at 8:02
source share



All Articles