您好我有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>
顯示你有什麼代碼,現在 –
剛剛發佈的代碼 – AC25
我如何使KeyBinding Key =「+」Modifiers =「Ctrl」工作? – AC25