KeyBinding does not support Click events #16313
Replies: 2 comments 6 replies
-
AFAIK, <Window x:Name="window" ....>
<Window.KeyBindings>
<KeyBinding Command="{Binding #window.SomeHotKey}" Gesture="Ctrl+S" />
</Window.KeyBindings>
... public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void SomeHotKey()
{
Trace.WriteLine("Hit");
}
} Alternatively, you could use KeyDown events in code-behind for everything. Communication across controls/VMs can be managed via messages if they aren't coupled. |
Beta Was this translation helpful? Give feedback.
-
@stevemonaco I gave this a shot as follows:
When pressing Ctrl+V my handler is not triggered and instead the app crashes with the following exception:
|
Beta Was this translation helpful? Give feedback.
-
IMHO proper MVVM means the VM has no concept of the platform it is running. In my case my VMs are in a .Net Core Library then reused on all platforms. Since some event handlers need to set focus to other controls, for example when pressing the Delete button to delete an item from a list, code behind must be used. A work around it to monitor the DataContext then assign a callback function to the VM's command handler, however, when sharing components between views this is problematic. KeyBindings should support both Command and Click options allowing both scenarios, MVVM and code behind.
Beta Was this translation helpful? Give feedback.
All reactions