GestureRecognizer 类

定义

识别墨迹笔势。

public ref class GestureRecognizer sealed : System::Windows::DependencyObject, IDisposable
public sealed class GestureRecognizer : System.Windows.DependencyObject, IDisposable
type GestureRecognizer = class
    inherit DependencyObject
    interface IDisposable
Public NotInheritable Class GestureRecognizer
Inherits DependencyObject
Implements IDisposable
继承
实现

示例

以下示例演示如何确定某个 Stroke 手势是否为 ScratchOut 手势。

private bool InterpretScratchoutGesture(Stroke stroke)
{
    // Attempt to instantiate a recognizer for scratchout gestures.
    ApplicationGesture[] gestures = { ApplicationGesture.ScratchOut };
    GestureRecognizer recognizer = new GestureRecognizer(gestures);

    if (!recognizer.IsRecognizerAvailable)
        return false;

    // Determine if the stroke was a scratchout gesture.
    StrokeCollection gestureStrokes = new StrokeCollection();
    gestureStrokes.Add(stroke);

    ReadOnlyCollection<GestureRecognitionResult> results = recognizer.Recognize(gestureStrokes);

    if (results.Count == 0)
        return false;

    // Results are returned sorted in order strongest-to-weakest; 
    // we need only analyze the first (strongest) result.
    if (results[0].ApplicationGesture == ApplicationGesture.ScratchOut &&
          results[0].RecognitionConfidence == RecognitionConfidence.Strong)
    {
        // Use the scratchout stroke to perform hit-testing and 
        // erase existing strokes, as necessary.
        return true;
    }
    else
    {
        // Not a gesture: display the stroke normally.
        return false;
    }
}
Private Function InterpretScratchoutGesture(ByVal stroke As Stroke) As Boolean
    ' Attempt to instantiate a recognizer for scratchout gestures.
    Dim gestures() As ApplicationGesture = {ApplicationGesture.ScratchOut}

    Dim recognizer As New GestureRecognizer(gestures)

    If Not recognizer.IsRecognizerAvailable Then
        Return False
    End If

    ' Determine if the stroke was a scratchout gesture.
    Dim gestureStrokes As StrokeCollection = New StrokeCollection()
    gestureStrokes.Add(stroke)

    Dim results As ReadOnlyCollection(Of GestureRecognitionResult)
    results = recognizer.Recognize(gestureStrokes)

    If results.Count = 0 Then
        Return False
    End If

    ' Results are returned sorted in order strongest-to-weakest; 
    ' we need only analyze the first (strongest) result.
    If (results(0).ApplicationGesture = ApplicationGesture.ScratchOut) Then

        ' Use the scratchout stroke to perform hit-testing and 
        ' erase existing strokes, as necessary.
        Return True
    Else
        ' Not a gesture: display the stroke normally.
        Return False
    End If
End Function

注解

GestureRecognizer标识墨迹笔势。 可以设置 GestureRecognizer 用于识别应用程序手势的所有或子集。 若要设置 GestureRecognizer 识别可用手势的子集,请将数组传递给 ApplicationGesture 构造函数或使用 SetEnabledGestures 该方法。 若要确定 StrokeCollection 是否包含手势,请调用 Recognize 该方法。

XAML 文本用法

不能在 XAML 中使用此类。

构造函数

名称 说明
GestureRecognizer()

初始化 GestureRecognizer 类的新实例。

GestureRecognizer(IEnumerable<ApplicationGesture>)

初始化 GestureRecognizer 类的新实例。

属性

名称 说明
DependencyObjectType

获取包装 DependencyObjectType 此实例的 CLR 类型。

(继承自 DependencyObject)
Dispatcher

获取与此DispatcherDispatcherObject关联的值。

(继承自 DispatcherObject)
IsRecognizerAvailable

获取一个布尔值,该值指示手势识别器是否在用户的系统上可用。

IsSealed

获取一个值,该值指示此实例当前是否密封(只读)。

(继承自 DependencyObject)

方法

名称 说明
CheckAccess()

确定调用线程是否有权访问此 DispatcherObject权限。

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

清除属性的本地值。 要清除的属性由 DependencyProperty 标识符指定。

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只读属性的本地值。 要清除的属性由一个 DependencyPropertyKey.

(继承自 DependencyObject)
CoerceValue(DependencyProperty)

强制指定依赖属性的值。 这是通过调用中调用依赖属性CoerceValueCallback的属性元数据中指定的任何DependencyObject函数来实现的。

(继承自 DependencyObject)
Dispose()

释放该 GestureRecognizer命令使用的所有资源。

Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObject

(继承自 DependencyObject)
GetEnabledGestures()

获取识别的 GestureRecognizer 手势。

GetHashCode()

获取此 DependencyObject代码的哈希代码。

(继承自 DependencyObject)
GetLocalValueEnumerator()

创建一个专用枚举器,用于确定哪些依赖项属性具有本地 DependencyObject设置的值。

(继承自 DependencyObject)
GetType()

获取当前实例的 Type

(继承自 Object)
GetValue(DependencyProperty)

返回此实例 DependencyObject上的依赖属性的当前有效值。

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。

(继承自 DependencyObject)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每当更新此 DependencyObject 属性上任何依赖属性的有效值时调用。 在事件数据中报告更改的特定依赖属性。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

返回依赖属性的本地值(如果存在)。

(继承自 DependencyObject)
Recognize(StrokeCollection)

查找指定 StrokeCollection中的手势。

SetCurrentValue(DependencyProperty, Object)

设置依赖项属性的值,而不更改其值源。

(继承自 DependencyObject)
SetEnabledGestures(IEnumerable<ApplicationGesture>)

设置识别的应用程序手势 GestureRecognizer

SetValue(DependencyProperty, Object)

设置依赖属性的本地值,由依赖属性标识符指定。

(继承自 DependencyObject)
SetValue(DependencyPropertyKey, Object)

设置只读依赖属性的本地值,由 DependencyPropertyKey 依赖属性的标识符指定。

(继承自 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。

(继承自 DependencyObject)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
VerifyAccess()

强制调用线程有权访问此 DispatcherObject权限。

(继承自 DispatcherObject)

适用于