如何从自定义绑定中获取MenuItem的Header值?

时间:2013-06-24 09:37:28

标签: wpf menuitem commandbinding custom-binding

我已在我的课程和XAML中定义 RoutedCommand

Public Shared CustomCommandShowAll As New RoutedCommand

Public Shared CustomCommandFirstPage As New RoutedCommand

Public Shared CustomCommandSecondPage As New RoutedCommand



<Window.CommandBindings>
        <CommandBinding Command="local:DynamicTab.CustomCommandShowAll" Executed="ShowAll_Executed" />
        <CommandBinding Command="local:DynamicTab.CustomCommandFirstPage" Executed="FirstPage_Executed" />
        <CommandBinding Command="local:DynamicTab.CustomCommandSecondPage" Executed="Secondpage_Executed" />
    </Window.CommandBindings>

    <Window.InputBindings>
        <KeyBinding Command="local:DynamicTab.CustomCommandShowAll" Key="F1" Modifiers="Alt"/>
        <KeyBinding Command="local:DynamicTab.CustomCommandFirstPage" Key="F2" Modifiers="Alt"/>
        <KeyBinding Command="local:DynamicTab.CustomCommandSecondPage" Key="F3" Modifiers="Alt"/>
    </Window.InputBindings>

这些绑定由菜单项

连接
<Menu DockPanel.Dock="Top" >

                <MenuItem x:Name="filtermenu" Header="_FilterType" BorderBrush="White" >

                    <MenuItem Header="ShowAll" IsChecked="True" InputGestureText="Alt+F1"/>

                    <MenuItem Header="FirstPage" InputGestureText="Alt+F2"/>

                    <MenuItem Header="Secondpage" InputGestureText="Alt+F3"/>
                </MenuItem>
            </Menu>

现在,当我按 ALT + F1 时, ShowAll_Executed 方法将接到一个电话,此处我有两个参数 ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs

    Private Sub ShowAll_Executed(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)

End Sub

我不知道如何从这两个参数中获取 ShowAll * MenuItem标题名称 *,如果我得到该值,我只能使用一个 RoutedCommand 所有三个MenuItems。提前谢谢。

0 个答案:

没有答案