Wpf 使用非字符键创建热键的按钮

Wpf 使用非字符键创建热键的按钮,wpf,xaml,Wpf,Xaml,嗨,我有wpf xaml按钮,我正在尝试为该按钮制作热键。我找到了密码 此代码工作正常,但我正在尝试添加第三个按钮,并将键值设为加号(“+”),如下所示: 当我尝试这样做时,我得到一个错误,无法转换“+”。任何帮助都将不胜感激 所有代码: <Window x:Class="WpfSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml

嗨,我有wpf xaml按钮,我正在尝试为该按钮制作热键。我找到了密码 此代码工作正常,但我正在尝试添加第三个按钮,并将键值设为加号(“+”),如下所示: 当我尝试这样做时,我得到一个错误,无法转换“+”。任何帮助都将不胜感激

所有代码:

   <Window x:Class="WpfSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <RoutedUICommand x:Key="MyCommand1" Text="Text" />
        <RoutedUICommand x:Key="MyCommand2" Text="Another Text" />
        <RoutedUICommand x:Key="MyCommand3" Text="Another Text 2" />
    </Window.Resources>

    <Window.CommandBindings>
        <CommandBinding Command="{StaticResource MyCommand1}" 
                    Executed="FirstMethod" />
        <CommandBinding Command="{StaticResource MyCommand2}" 
                    Executed="SecondMethod" />
        <CommandBinding Command="{StaticResource MyCommand3}" 
                    Executed="ThirdMethod" />
    </Window.CommandBindings>

    <Window.InputBindings>
        <KeyBinding Key="Z" Modifiers="Ctrl" Command="{StaticResource MyCommand1}" />
        <KeyBinding Key="A" Modifiers="Ctrl" Command="{StaticResource MyCommand2}" />
        <KeyBinding Key="+" Modifiers="Ctrl" Command="{StaticResource MyCommand3}" />
    </Window.InputBindings>

    <Grid>
        <Button x:Name="btn1" Command="{StaticResource MyCommand1}" Content="Click me"                 Visibility="Collapsed" />
        <Button x:Name="btn2" Command="{StaticResource MyCommand2}" Content="Click me" Visibility="Collapsed" />
        <Button x:Name="btn3" Command="{StaticResource MyCommand3}" Content="Click me" Visibility="Collapsed" />
    </Grid>

</Window>

您可能正在查找
OemPlus
Add
键:

<KeyBinding Key="OemPlus" Modifiers="Ctrl" Command="{StaticResource MyCommand3}" />
<KeyBinding Key="Add" Modifiers="Ctrl" Command="{StaticResource MyCommand3}" />


显示您现在拥有的代码如何使KeyBinding Key=“+”Modifiers=“Ctrl”工作?这是否允许我点击Ctrl和加号(+)Ctrl++,因为它清除了错误,但我没有从附加的函数中获得任何代码