简体   繁体   English

只有最后一个MenuItem获得图标

[英]Only the last MenuItem gets the Icon

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>

This is used inside 这用在里面

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

I tried the x:Share too but this didn't work cause of ResourceDictionary in a ResourceDictionary. 我也尝试了x:Share,但这在ResourceDictionary中没有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>

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. 单独将图标添加到任何条目都无法解决我的问题,因为在我的应用程序中大约有200个项目。

Best Regards 最好的祝福

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>

Here the x:Share works fine. 在这里x:Share工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM