Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Test/UnitTests/KeyTriggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -148,7 +162,6 @@ public void KeyTrigger_InvokesActions_WhenKeyIsReleased(Key key)
}
}


[TestMethod]
[DataRow(true)]
[DataRow(false)]
Expand Down
6 changes: 4 additions & 2 deletions src/Microsoft.Xaml.Behaviors/Input/KeyTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down