我有一个WPF上下文菜单,我想在我的C#代码中添加带有Icon的Item。 我怎么能这样做?
答案 0 :(得分:2)
已经有这样的问题了。例如here。 所以你不必在这里向下钻取:
menuItem.Icon = new BitmapImage(new Uri("images/sample.png", UriKind.Relative));
答案 1 :(得分:1)
应该适合你。
<ContextMenu x:Key="MyContextMenu" >
<MenuItem Header="Item1" Click="Ietm1_Click"
Icon="{StaticResource ItemIco}" />
</ContextMenu>
并且可以通过此cose
访问资源中的某人<Image x:Key="ItemIco" Source="Images/ItemIco.png"/>
在这种情况下,Images
,natuarally,是一个实际路径的文件夹。