KeyGesture.Matches(Object, InputEventArgs) Method

Definition

Determines whether this KeyGesture matches the input associated with the specified InputEventArgs object.

C#
public override bool Matches(object targetElement, System.Windows.Input.InputEventArgs inputEventArgs);

Parameters

targetElement
Object

The target.

inputEventArgs
InputEventArgs

The input event data to compare this gesture to.

Returns

true if the event data matches this KeyGesture; otherwise, false.

Examples

The following example shows how to test whether a KeyGesture matches the input associated with an instance of an InputEventArgs. A KeyDown event handler is created that compares the event data with the KeyGesture by using the Matches method.

C#
private void OnKeyDown(object sender, KeyEventArgs e)
{
    KeyGesture keyGesture = new KeyGesture(Key.B, ModifierKeys.Control);

    if(keyGesture.Matches(null, e))
    {
        MessageBox.Show("Trapped Key Gesture");
    }
}

Remarks

targetElement can be used to make a more specific decision on whether a command should be invoked on a specific element.

Applies to

Produkt Versioner
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10