MenuItem style with icon creates only one icon

前端 未结 1 1756
盖世英雄少女心
盖世英雄少女心 2020-11-29 02:44

Im having a problem rendering icons for a dynamic menu which uses viewmodels as an ItemsSource.
The solution I\'ve used is outlined here MVVM Dynamic Menu UI from bindi

相关标签:
1条回答
  • 2020-11-29 03:22

    Add x:Shared=false for your Icon value. To do that you should declare Image in resources:

    <Grid>
      <Grid.Resources>
    
       <Image x:Key="imgCTX" x:Shared="false"
             Source="{Binding Path=Icon}" Height="16px" Width="16px"/>
        <HierarchicalDataTemplate DataType="{x:Type ViewModels:HeaderedItemViewModel}"
            ItemsSource="{Binding Path=Children}">
          <ContentPresenter RecognizesAccessKey="True"></ContentPresenter>
        </HierarchicalDataTemplate>
        <Style TargetType="{x:Type MenuItem}">
          <Setter Property="Header" Value="{Binding Path=Header}" />
          <Setter Property="InputGestureText" Value="{Binding Path=InputGestureText}" />
          <Setter Property="Command" Value="{Binding Path=Command}" />
          <Setter Property="Icon" Value="{StaticResource imgCTX}" />
        </Style>
      </Grid.Resources>
      <Menu Grid.Row="0" ItemsSource="{Binding Path=Shell.Navigation.Menus}" />
    </Grid>
    
    0 讨论(0)
提交回复
热议问题