GestureRecognizer 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
识别墨迹笔势。
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 |
获取与此 Dispatcher 关联的 DispatcherObject。 (继承自 DispatcherObject) |
IsRecognizerAvailable |
获取一个布尔值,该值指示笔势识别器在用户系统中是否可用。 |
IsSealed |
获取一个值,该值指示此实例当前是否为密封的(只读)。 (继承自 DependencyObject) |