您好我有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>
答案 0 :(得分:0)
您可能正在寻找OemPlus
或Add
密钥:
<KeyBinding Key="OemPlus" Modifiers="Ctrl" Command="{StaticResource MyCommand3}" />
<KeyBinding Key="Add" Modifiers="Ctrl" Command="{StaticResource MyCommand3}" />