Edit

Share via


KeyGesture.Matches(Object, InputEventArgs) Method

Definition

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

public:
 override bool Matches(System::Object ^ targetElement, System::Windows::Input::InputEventArgs ^ inputEventArgs);
public override bool Matches (object targetElement, System.Windows.Input.InputEventArgs inputEventArgs);
override this.Matches : obj * System.Windows.Input.InputEventArgs -> bool
Public Overrides Function Matches (targetElement As Object, inputEventArgs As InputEventArgs) As Boolean

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.

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");
    }
}
Private Overloads Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
    Dim keyGesture As New KeyGesture(Key.B, ModifierKeys.Control)

    If keyGesture.Matches(Nothing, e) Then
        MessageBox.Show("Trapped Key Gesture")
    End If
End Sub

Remarks

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

Applies to