WPF 菜单项图标的图像应该是什么大小和格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14503204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What size and format should image for WPF MenuItem Icon be?
提问by Colonel Panic
What size and format should a WPF MenuItem Icon be to look right?
WPF 菜单项图标应该是什么大小和格式才能看起来正确?
Right now I have
现在我有
<ContextMenu>
<MenuItem Header="Camera">
<MenuItem.Icon>
<Image Source="images/camera.png" />
</MenuItem.Icon>
But in the menu, the icon spills over margin, which looks bad.
但是在菜单中,图标溢出边缘,看起来很糟糕。
Frustratingly, the docs don't give this information. System.Windows.Controls.MenuItem.Icon
令人沮丧的是,文档没有提供这些信息。 System.Windows.Controls.MenuItem.Icon
回答by Ionic? Biz?u
I think that the right size of image would be 20px.
我认为合适的图像尺寸是20px.
Just specify the Widthand the Heigthof your image:
只需指定图像的Width和Heigth:
Use this:
用这个:
<MenuItem.Icon>
<Image Source="images/camera.png"
Width="20"
Height="20" />
</MenuItem.Icon>
...
回答by MikroDel
this is the code:
这是代码:
<MenuItem>
<MenuItem.Header>
<StackPanel>
<Image Width="20" Height="20" Source="PATH to your image" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
You can also try stretch Image.Stretch Property
您也可以尝试拉伸 Image.Stretch 属性

