Global keybindings in Noesis
Posted: 12 Apr 2016, 11:48
I am creating a Unity application using NoesisGUI. My NoesisGUIPanel uses a UserControl named LayoutRoot as root for the GUI.
Inside this app, I have a button, let's call it ActionButton, which is a UserControl that is used in various views (but not all) in the app. Whenever ActionButton is used in a view, I'd like the Enter key to trigger the command tied to ActionButton.
At first I tried adding a KeyBinding to the InputBindings of ActionButton like this (hiding a bunch of irrelevant stuff for brevity):
This did not work. I figured it was because the ActionButton did not have application focus, so I tried defining a KeyBinding in LayoutRoot (the XAML root of the project) to see if focus was the problem:
My theory was that if defined at the root, the InputBinding would always have focus, but the command won't trigger anyways. What am I doing wrong here?
Inside this app, I have a button, let's call it ActionButton, which is a UserControl that is used in various views (but not all) in the app. Whenever ActionButton is used in a view, I'd like the Enter key to trigger the command tied to ActionButton.
At first I tried adding a KeyBinding to the InputBindings of ActionButton like this (hiding a bunch of irrelevant stuff for brevity):
Code: Select all
<UserControl
x:Name="ActionButtonControl"
x:Class="MyNamespace.ActionButton">
<UserControl.InputBindings>
<!-- The ActionButton code behind defines a DependencyProperty named CommandProperty -->
<KeyBinding Command="{Binding Command,ElementName=ActionButtonControl}" Gesture="Enter" />
</UserControl.InputBindings>
<Grid>
<Button Content="" Command="{Binding Command,ElementName=ActionButtonControl}" />
</Grid>
</UserControl>
Code: Select all
<UserControl
x:Class="MyNamespace.LayoutRoot"
x:Name="Root">
<UserControl.InputBindings>
<KeyBinding Command="{Binding SomeCommand}" Gesture="Enter" />
</UserControl.InputBindings>
<Grid>
<!-- Application contents here>
</Grid>
</UserControl>