Is it possible to dynamically determine KeyBindings based on a linked data source? I have a screen with a grid, and I allow users to save various layouts for it. I am currently associating a grid context menu with layout names (via the ViewModel), allowing them to switch with layouts through the menu.
However, I would like to associate each layout with a keyboard shortcut. Since shortcuts are user-defined, I can't just add a few <KeyBinding> elements to the XAML window. Another problem is that the binding should indicate the layout name as a parameter to the command.
Is there a way to dynamically create a series of <KeyBinding> elements from a dynamic source?
As a test, I added bindings statically to my XAML view, and they work fine, but this was only to test my concept:
<UserControl.InputBindings> <KeyBinding Key="F7" Command="{Binding MyCommand}" CommandParameter="My Layout Name"/> <KeyBinding Key="F8" Command="{Binding MyCommand}" CommandParameter="My Other Layout Name"/> </UserControl.InputBindings>
source share