在Blend中的MenuItem控件中加入图片

本文介绍了在WPF中为MenuItem添加图标的方法。由于Blend工具中的ICON属性存在问题,无法直接设置图标,可以通过手动编辑XAML文件来实现。具体做法是在MenuItem的Icon属性中插入ImageSource。

最近搞WPF遇到需要在MenuItem中加入图片,直接的ICON属性不能修改。

在国外的一个网站上找到了相关的讨论资料,原文如下:

http://social.expression.microsoft.com/Forums/en-US/blend/thread/b25a0df8-77d4-49b3-a891-61fb3488b9ac/

 

Q:

I've looked all over for this, and tried a ton of methods, but I can not make an image that I assign with blend actually show up using blend.  Maybe I'm just doing it wrong.
I can directly edit the XAML file and put in code like:
<MenuItem.Icon>
    <Image Source="{DynamicResource MyImage}"/>
</MenuItem.Icon>

this will show the image, but the idea is to not just get the goal done, but use Blend to do it.

Thanks,
Jim
A:
Howdy,

At the moment, the ICON property of the MenuItem is not correctly defined in order for you to be able to add an image as such. The ICON is of type "object" which isnt what I would expect, but it is because of this reason that the property is also disabled.

So to answer your question, you must manually add the XAML as you have.

Cheers
大概意思就是 Blend下 MenuItem 的 ICON属性还有问题没有解决,所以只能通过手动在XAML文件中添加代码,代码就如提问者的方式
实践的代码:
   <MenuItem Header="在线" Background="#FFDEF3FF">
       <MenuItem.Icon>
           <Image Source="Images/QQ_Online.bmp" Width="16" Height="16" />
       </MenuItem.Icon>
   </MenuItem>
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值