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 |
取得布林 (Boolean) 值,指出使用者的系統上是否有可用的筆勢辨識器。 |
IsSealed |
取得值,這個值表示此執行個體目前是否已密封 (唯讀)。 (繼承來源 DependencyObject) |