我有以下XAML
加载菜单和菜单项的内容,但是有没有办法绑定命令/输入手势而不必使用StackPanel
?CmdParam
是我的 VM 中具有该命令的属性。我最初想在下面的资源部分中设置它,但命令没有显示
<Window>
<Window.Resources>
<Style TargetType="{x:Type MenuItem}" x:Key="menuSeparatorStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Separator HorizontalAlignment="Stretch" IsEnabled="false"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="InputGestureText" Value="{Binding CmdParam}"/>
</Style>
<HierarchicalDataTemplate DataType="{x:Type projectBusinessLayer:MenuDataItem}">
<ContentPresenter Content="{Binding Path=MenuText}" Loaded="OnMenuDataItemLoaded" RecognizesAccessKey="True" />
<HierarchicalDataTemplate.ItemsSource>
<Binding Path="MenuItemID">
<Binding.Converter>
<converters:MenuDataItemConverter />
</Binding.Converter>
</Binding>
</HierarchicalDataTemplate.ItemsSource>
</HierarchicalDataTemplate>
<projectBusinessLayer:MenuSeparatorStyleSelector x:Key="menuSeparatorStyleSelector"/>
</Window.Resources>
<DockPanel>
<Menu x:Name="mnuMainMenu" ItemsSource="{Binding}" VerticalAlignment="Top" DockPanel.Dock="Top" ItemContainerStyleSelector="{StaticResource menuSeparatorStyleSelector}"/>
</DockPanel>