There is a MenuItem , which is filled with other MenuItem items using the Binding . Fragment of the XAML file:
<MenuItem x:Name="FileCommands" Header="{DynamicResource menu_File}" ItemsSource="{Binding Path=Commands}"> <MenuItem.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}"> <Setter Property="InputGestureText" Value="{Binding InputGestureText}" /> <Setter Property="Command" Value="{Binding Path=Command}" /> </Style> </MenuItem.ItemContainerStyle> <MenuItem.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Commands}"> <MenuItem Header="{Binding Path=DisplayName}" /> </HierarchicalDataTemplate> </MenuItem.ItemTemplate> In this version of the menu is displayed as follows:
When compared with the correct display of the menu, the difference is obvious:
As you can see, if the MenuItem not displayed correctly, MenuItem element has two selection areas, internal and external, and the Command only works when you click on the external selection area. However, if I change an item in the HierarchicalDataTemplate from the MenuItem to the TextBlock like this:
<HierarchicalDataTemplate ItemsSource="{Binding Path=Commands}"> <TextBlock Text="{Binding Path=DisplayName}" /> </HierarchicalDataTemplate> , the menu is displayed correctly, but with one feature. It seems to me that because it is not MenuItem that is used, TextBlock ignores underscores, which are used for quick access to menu items while the Alt key is held down and the text is displayed as is. It looks like this:
I think this is not the only difference TextBlock from the MenuItem and there may be some other pitfalls that can be encountered in the future.
The question is: is it possible to display the MenuItem correctly, or will you have to sacrifice the ability to quickly access the menu items while holding the Alt key (if this is of course the only difference TextBlock from the MenuItem )?



HierarchicalDataTemplatewith your specified solution? If yes, could you give us an example of use? If that doesn't bother you, of course. - XelaNimed