无法通过setter设置System.Windows.Controls.MenuItem.Icon [英] Unable to set System.Windows.Controls.MenuItem.Icon thru a setter
问题描述
您好我正在尝试 MenuItem.Icon 通过样式设置器设置:
Hi I am trying to have a MenuItem.Icon set thru a style setter:
<Style x:Key="MenuItem_Delete" TargetType="MenuItem"
BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="_Delete"/>
<Setter Property="MenuItem.Icon">
<Setter.Value>
<Image Source="Resources/Delete.png"/>
</Setter.Value>
</Setter>
</Style>
我在运行时收到以下异常:
无法添加'System.Windows类型的内容.Controls.Image'到'System.Object'类型的对象。标记文件'WpfApplication1; component / application.xaml'中对象'System.Windows.Controls.Image'出错。第164行第26位。
I get the following exception at runtime: Cannot add content of type 'System.Windows.Controls.Image' to an object of type 'System.Object'. Error at object 'System.Windows.Controls.Image' in markup file 'WpfApplication1;component/application.xaml' Line 164 Position 26.
另一方面,这个是以上链接中的示例:
In the other hand, this is the example in the above link:
<MenuItem Header="New">
<MenuItem.Icon>
<Image Source="data/cat.png"/>
</MenuItem.Icon>
</MenuItem>
谢谢。
推荐答案
我绝望地在网上搜索答案,我认为这是一个WPF错误。
I was desperatly searching the web for an answer and I think this is a WPF bug.
我报告了它@ Microsoft Connect ,如果你有的话,请投票并验证或与微软分享您的想法。
I reported it @ Microsoft Connect, please vote and validate or share your ideas with Microsoft if you have some.
更新
这篇帖子对我帮助很大。
Update
This post helped me a lot.
这篇关于无法通过setter设置System.Windows.Controls.MenuItem.Icon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!