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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:12:56  来源:igfitidea点击:

What size and format should image for WPF MenuItem Icon be?

c#.netwpfxaml

提问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:

只需指定图像的WidthHeigth

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 属性