Here is the actual XAML code:

<Menu Height="25" VerticalAlignment="Top" HorizontalAlignment="Stretch"> <MenuItem Header="File"> <MenuItem Header="Field Size"> <ItemsControl ItemsSource="{Binding AllMenuItems}" Grid.Column="0"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate DataType="{x:Type vm:MenuVM}" > <MenuItem Command="{Binding Activate}" Width="50" Height="25" > <TextBlock Text="{Binding NameOfField}"></TextBlock> </MenuItem> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </MenuItem> </MenuItem> </Menu> 

Binding neither Command, nor Text'a does not work, what is the error? Binding ItemsSourse works, displays 4 items of type MenuItem

  • where do you have a team? in class where and AllMenuItems? if so, then you need to bind it differently - Gardes

1 answer 1

You somehow complicate things a lot.

MenuItem itself is an ItemsControl , so your code is simplified to this:

 <Menu Height="25" VerticalAlignment="Top" HorizontalAlignment="Stretch"> <MenuItem Header="File"> <MenuItem Header="Field Size" ItemsSource="{Binding AllMenuItems}"> <MenuItem.ItemContainerStyle> <Style TargetType="MenuItem"> <Setter Property="Header" Value="{Binding NameOfField}"/> <Setter Property="Command" Value="{Binding Activate}"/> </Style> </MenuItem.ItemContainerStyle> </MenuItem> </MenuItem> </Menu> 

It turns out this:

open menu