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

查看:24
本文介绍了只有最后一个 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.

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天全站免登陆