-
Notifications
You must be signed in to change notification settings - Fork 142
Closed
Description
Summary
The following definition does not result into the invocation of a command
<b:KeyTrigger Key="LeftCtrl" FiredOn="KeyUp">
<b:InvokeCommandAction Command="..." />
</b:KeyTrigger>
(That same behavior is for any modifier key.)
To reproduce
- Build and run the following WPF app project (.NET Framework 4.7.2): KeyTriggerDemo.zip
- Press the LEFT CTRL key several times
Expected behavior: Two lines are displayed: "UP UP UP..." and "DOWN DOWN DOWN..."
Observed behavior: No "UP"s are displayed.
Reason
The root cause is in the KeyTrigger.cs file:
XamlBehaviorsWpf/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs
Lines 74 to 81 in 7c79fe9
private void OnKeyPress(object sender, KeyEventArgs e) | |
{ | |
if (e.Key == this.Key && | |
Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers)) | |
{ | |
this.InvokeActions(e); | |
} | |
} |
When the CTRL key is UP, the Keyboard.Modifiers
is None
(at least it has CTRL off), however GetActualModifiers
returns the instance with CTRL on. Thus, the if
condition returns false
and actions are not invoked.
Is that by design or a bug?
Metadata
Metadata
Assignees
Labels
No labels