There is a number of keyboard shortcuts that I'd like to be available application-wide, regardless of where the focus currently is.
At the moment I've got those defined as <Window.InputBindings>
in my Main window's XAML.
All is good, but...
The Ribbon is encapsulated as a separate UserControl, and all the shortcuts are, naturally, related to the buttons that are in that Ribbon.
Consequently, I don't really like the smell of having 2 pieces of application logic dealing with the same functionality spread across the 2 classes.
Ideally, I would like to define the KeyBindings as <Window.InputBindings>
, but in the UserControl, not in the window. Obviously, that cannot be done with XAML syntax, but only <UserControl.InputBindings>
- alas, that would make them available only when the focus is on the Ribbon (which means never).
Any suggestions?
Thanks, Alex
In the constructor of your control or in its Loaded() event handler, have it find the window in which it stands (use VisualTreeHelper.GetParent(this) recursively until GetType is Window...), then add the InputBindings you want to that window.