How to define MenuItem.Icon so that the MenuItemHeader text would be placed below the menu item image?Thanks for help!
How to define MenuItem.Icon so that the MenuItemHeader text would be placed below the menu item image?Thanks for help!
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.
MenuItem.Icon
and the below answer just shows the usage of MenuItem.Icon
so its basically what OP said is is currently using but he doesn't want the Image to be on the left side of the text, but below of it. so the high voted answer is simply wrong for OP's actual question. –
Mosera How something along the lines of:
<ContextMenu>
<MenuItem Header="Reports">
<MenuItem.Icon>
<Image Source="/XSoftArt.WPFengine;component/Images/export32x32xp.png"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
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.
MenuItem.Icon
and the below answer just shows the usage of MenuItem.Icon
so its basically what OP said is is currently using but he doesn't want the Image to be on the left side of the text, but below of it. so the high voted answer is simply wrong for OP's actual question. –
Mosera 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.
This works for me:
<Menu Height="22" Grid.Row="0">
<MenuItem Header="View">
<MenuItem Header="Form"/>
</MenuItem>
<MenuItem Header="Tools">
<MenuItem Header="Options...">
<MenuItem.Icon>
<Image Source="./Images/Menu/settings.png"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
And you must change the build type of the image to Resource
.
© 2022 - 2024 — McMap. All rights reserved.