2014-01-24 25 views
0

您好我有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

剛剛發佈的代碼 – AC25

+0

我如何使KeyBinding Key =「+」Modifiers =「Ctrl」工作? – AC25

回答

0

你可能尋找OemPlusAdd鍵:

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

這將允許我點擊Ctrl和加號(+)Ctrl ++,因爲它清除了錯誤,但我沒有得到任何附加函數的代碼 – AC25

+0

是的,這應該適用於CTRL +(+) –