只有最后一个MenuItem获得图标 [英] Only the last MenuItem gets the Icon

查看:105
本文介绍了只有最后一个MenuItem获得图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道还有其他线程,但就我而言,情况有些不同。

I know there are other threads about this but in my case its a bit different.

我喜欢使用来自单独资源程序集的图标

I like to use an icon from a separate resource assembly

    <MultiTrigger>
      <MultiTrigger.Conditions>
      <Condition Property="IsCheckable"
                 Value="true" />
      <Condition Property="IsChecked"
                 Value="true" />
      <Condition Property="Role"
                 Value="SubmenuItem" />
      </MultiTrigger.Conditions>
      <Setter Property="Icon">
        <Setter.Value>
          <Image Margin="1,0"
                 Width="16"
                 Source="pack://application:,,,/MyResourceAssembly;
                         component/Resources/Connect_24.png"/>
        </Setter.Value>
      </Setter>
    </MultiTrigger>

在内部使用

<Style TargetType="{x:Type MenuItem}">

我也尝试了x:Share,但这在ResourceDictionary中没有ResourceDictionary的原因。 / p>

I tried the x:Share too but this didn't work cause of ResourceDictionary in a ResourceDictionary.

    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="pack://application:,,,/MyResourceAssembly;component/Resources.xaml" />

      <ResourceDictionary>
        <Image x:Key="ConnectedIcon"
               x:Shared="false"
               Margin="1,0"
               Width="16"
               Source="pack://application:,,,/MyResourceAssembly;component/Resources/Connect_24.png"/>
      </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>

有人能解决这个问题吗?单独将图标添加到任何条目都不能解决我的问题,因为在我的应用程序中,大约有200个项目。

Do anybody has an idea to solve this problem. Adding the icon to any entry separately didn't solve the issue for me, cause in my application are about 200 items.

最诚挚的问候

推荐答案

在正确位置的资源可以解决问题。

The resource at the right place solves the problem.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Image x:Key="ConnectedIcon"
           x:Shared="False"
           Source="pack://application:,,,/MyResourceAssembly;component/Resources/Connect_24.png"
           Margin="1,0"
           Width="16"/>
</ResourceDictionary>

在这里x:Share工作正常。

Here the x:Share works fine.

这篇关于只有最后一个MenuItem获得图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆