带图像的WPF菜单项 [英] WPF menu item with image
问题描述
如何定义MenuItem.Icon以便MenuItemHeader文本放在菜单项图像下面?感谢您的帮助!
How to define MenuItem.Icon so that the MenuItemHeader text would be placed below the menu item image?Thanks for help!
推荐答案
简单的方法是不使用Icon属性,而是将图标放在标题中:
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>
对于这个简单的情况,< ContentPresenter Content =Reports/> ;
可以替换为< TextBlock Text =Reports/>
,因为这就是ContentPresenter用于呈现字符串的方式。对于更复杂的 Header =
,您可以使用 ContentPresenter
,如图所示。
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.
这篇关于带图像的WPF菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!