KeyGesture.Matches Method (Object, InputEventArgs)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public override bool Matches(
	object targetElement,
	InputEventArgs inputEventArgs
)

Parameters

targetElement
Type: System.Object

The target.

inputEventArgs
Type: System.Windows.Input.InputEventArgs

The input event data to compare this gesture to.

Return Value

Type: System.Boolean

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

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

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");
    }
}

.NET Framework
Available since 3.0
Return to top
Show: