I’m working on a WPF application in which I have a MainWindow of type RibbonWindow and (obviously) a Ribbon control in it; I’m trying to add KeyGestures to some commands that come from the viewmodel, but haven’t been able to, I’ve read a lot of questions and articles about and applied some of the answers given but haven’t been able to figure it out.
Some of the things I tried:
1 Add the KeyGesture from the code-behind (even testing with another command such as ApplicationCommands.Close):
private KeyGesture _closeGesture = new KeyGesture(Key.E, ModifierKeys.Control);
private KeyBinding _closeBinding;
//...
public MainWindow()
{
InitializeComponent();
_closeBinding = new KeyBinding(ApplicationCommands.Close, _closeGesture);
this.InputBindings.Add(_closeBinding);
}
2 Add the KeyGesture directly in the XAML:
<rcl:RibbonWindow.InputBindings>
<KeyBinding Command="ApplicationCommands.Close"
Key="E" Modifiers="Control" />
</rcl:RibbonWindow.InputBindings>
3 Add the KeyGesture with any of the above methods but binding it to the viewmodel’s command, and even implementing the RelayCommand with the KeyGesture in it.
I’ll appreciate any help you could give me.
i have used underneath code in my application and it’s working fine
my xaml code look like
in my viewmodel
k public ICommand ExitCommand