2010-11-09 82 views
0

我有密鑰綁定的問題。我無法爲「+」設置密鑰。有人可以幫助我,我應該在xaml中寫什麼,以及我應該用.cs寫入什麼?wpf中的密鑰綁定

+0

你能告訴我你已經試過了嗎? – ocodo 2010-11-09 12:28:48

回答

2

鍵綁定可以在Window級別設置,所以在XAML你添加...

<Window.InputBindings> 
    <KeyBinding Command="YourCommand" Key="+" /> 
</Window.InputBindings> 

我假設你知道如何提供CommandWindow.CommandBinding

+0

在我寫的.xaml.cs文件中 - public static RoutedCommand AddCommand = new RoutedCommand(); – userN 2010-11-10 05:38:07

+0

在我爲命令綁定編寫的另一個dll中(我也使用了命令綁定,它可以正常工作): private void AddCanExecute(object sender,CanExecuteRoutedEventArgs e) e.CanExecute = true; e.Handled = true; } private void AddExecute(object sender,ExecutedRoutedEventArgs e) ExecuteOperation(); _prevOperation = _math.Add; e.Handled = true; } – userN 2010-11-10 05:39:56

+0

在xaml中我按照你的說法寫了。調試後,沒有任何錯誤,但發生異常: 無法將屬性'Command'中的字符串'AddCommand'轉換爲'System.Windows.Input.ICommand'類型的對象。 CommandConverter不能從System.String轉換。對象'System.Windows.Input.KeyBinding'在標記文件'WPF計算器;組件/ window1.xaml'行14錯誤位置21. – userN 2010-11-10 05:41:04