XAML 组合键绑定命令
<Window.InputBindings>
双键
<KeyBinding Command="{Binding ButtonCommand}" Gesture="CTRL+R" />
仨键+参数
<KeyBinding Modifiers="Shift+Alt" Key="F1" CommandParameter="{Binding}" Command="{Binding ButtonCommand}"/>
仨键+参数+静态Command
<KeyBinding Modifiers="Shift+Alt" Key="C" CommandParameter="{Binding}" Command="{Binding Source={x:Static commands:CustomCommands.TestCommand}}"/>
</Window.InputBindings>
this.ButtonCommand = new DelegateCommand<object>(ButtonCommandMethod);
xaml命名空间引入
xmlns:commands="clr-namespace:Richen.WPF.UI.MagneticControl.Commands"
public class CustomCommands
{
private static DelegateCommand<object> _testCommand;
public static DelegateCommand<object> TestCommand
{
get {
if (_testCommand == null)
{ _testCommand = new DelegateCommand<object>(TestExecute, TestCanExecute); }
return _testCommand; }
}
public static bool TestCanExecute(object o) { return true; }
public static void TestExecute(object o) {}
}
下面这个好像不加也触发了
//Focusable = true;
//Loaded += (s, e) => Keyboard.Focus(this);
浙公网安备 33010602011771号