语言

KeyGesture.Matches(Object, InputEventArgs) 方法

定义

确定这 KeyGesture 是否与与指定 InputEventArgs 对象关联的输入匹配。

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

参数

targetElement
Object

目标。

inputEventArgs
InputEventArgs

要与此手势进行比较的输入事件数据。

返回

如果事件数据与此匹配,则为 /&;否则为 。

示例

下面的示例演示如何测试与与实例KeyGesture关联的输入是否InputEventArgs匹配。 创建一个KeyDown事件处理程序,用于使用KeyGesture该方法将事件数据与Matches该事件数据进行比较。

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

注解

targetElement 可用于对是否应在特定元素上调用命令做出更具体的决定。

适用于