There is a XAML:

<Menu Width="Auto"> <MenuItem ItemsSource="{Binding Path=листОбъектов, Source={x:Static тут:статичекий.синглтон.класса}}"> <MenuItem.Header> <Image Source="Какой_нибудь_путь_к_картинке" Width="16" Height="16"/> </MenuItem.Header> <MenuItem.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Header" Value="{Binding Path=TypeObjectName}"/> <Setter Property="Icon"> <Setter.Value> <Image Width="16" Height="16" Source="{Binding Path=IconSource}" /> </Setter.Value> </Setter> </Style> </MenuItem.ItemContainerStyle> </MenuItem> </Menu> 

IconSource is filled everywhere, but only the last item has icons in MenuItem .

  • one
    The problem is that the same UI element (for example, Image ) cannot be reused. And your Image from the style (it is there in one copy) is used for all item's! As far as I understand, your question has already been considered here: ru.stackoverflow.com/a/534269/10105 - VladD
  • (That is, there is an explanation not for your case, and the code will do for you.) - VladD
  • @VladD Well, I use the same method for the TreeView, but there were no problems. Now I will try - Dmitry Chistik

1 answer 1

Made through ItemTemplate, thanks @VladD for explanations

 <MenuItem.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Border BorderBrush="Black" BorderThickness="1"> <Grid> <Image Width="16" Height="16" Source="{Binding Path=IconSource}" /> <Image Source="Маханькая_иконошка" Width="8" Height="8" VerticalAlignment="Top" HorizontalAlignment="Left"/> </Grid> </Border> <TextBlock Grid.Column="1" Text="{Binding Path=TypeObjectName}"/> </Grid> </DataTemplate> </MenuItem.ItemTemplate>