This documentation is archived and is not being maintained.

GestureRecognizer.Recognize Method

Looks for gestures in the specified StrokeCollection.

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

public ReadOnlyCollection<GestureRecognitionResult> Recognize(
	StrokeCollection strokes
)

Parameters

strokes
Type: System.Windows.Ink.StrokeCollection
The StrokeCollection to search for gestures.

Return Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<GestureRecognitionResult>
An array of type GestureRecognitionResult that contains application gestures that the GestureRecognizer recognized.

The array returned by the Recognize method is sorted by the GestureRecognitionResult.RecognitionConfidence property. For example, Recognize may return a GestureRecognitionResult array with the following values:

Index

ApplicationGesture

RecognitionConfidence

0

Check

Strong

1

NoGesture

Intermediate

2

Curlicue

Poor

3

DoubleCurlicue

Poor

This means that the GestureRecognizer recognizes that it is very likely that the Stroke is a check mark, relatively likely that the Stroke in not a gesture, and not at all likely that the Stroke is a curlicue or a double curlicue.

NoteNote

The Recognize method can return an array with NoGesture at a higher RecognitionConfidence than other application gestures. This means that it is more likely that the Stroke is not a gesture, as opposed to a gesture that has a lower RecognitionConfidence.

The following example demonstrates how to determine whether a Stroke is a Scratchout() gesture.


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


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: