2010-11-09 119 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