diff --git a/Test/UnitTests/KeyTriggerTest.cs b/Test/UnitTests/KeyTriggerTest.cs index d754912..fddbff6 100644 --- a/Test/UnitTests/KeyTriggerTest.cs +++ b/Test/UnitTests/KeyTriggerTest.cs @@ -68,6 +68,13 @@ public void Teardown() [DataRow(Key.NumPad9)] [DataRow(Key.Enter)] [DataRow(Key.Tab)] + [DataRow(Key.LeftCtrl)] + [DataRow(Key.RightCtrl)] + [DataRow(Key.LeftAlt)] + [DataRow(Key.RightAlt)] + [DataRow(Key.System)] + [DataRow(Key.LeftShift)] + [DataRow(Key.RightShift)] public void KeyTrigger_InvokesActions_WhenKeyIsPressed(Key key) { var textBox = new TextBox(); @@ -127,6 +134,13 @@ public void KeyTrigger_InvokesActions_WhenKeyIsPressed(Key key) [DataRow(Key.NumPad9)] [DataRow(Key.Enter)] [DataRow(Key.Tab)] + [DataRow(Key.LeftCtrl)] + [DataRow(Key.RightCtrl)] + [DataRow(Key.LeftAlt)] + [DataRow(Key.RightAlt)] + [DataRow(Key.System)] + [DataRow(Key.LeftShift)] + [DataRow(Key.RightShift)] public void KeyTrigger_InvokesActions_WhenKeyIsReleased(Key key) { var textBox = new TextBox(); @@ -148,7 +162,6 @@ public void KeyTrigger_InvokesActions_WhenKeyIsReleased(Key key) } } - [TestMethod] [DataRow(true)] [DataRow(false)] diff --git a/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs b/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs index aece7b3..3fa8b87 100644 --- a/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs +++ b/src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs @@ -73,8 +73,10 @@ protected override string GetEventName() private void OnKeyPress(object sender, KeyEventArgs e) { - if (e.Key == this.Key && - Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers)) + bool isKeyMatch = e.Key == this.Key; + bool isModifiersMatch = this.Modifiers == ModifierKeys.None ? true : Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers); + + if (isKeyMatch && isModifiersMatch) { this.InvokeActions(e); }