Export (0) Print
Expand All

RecognitionResult.SetResultOnStrokes Method

Assigns the RecognitionResult object to the Strokes collection that was used to generate the results.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

public void SetResultOnStrokes()

System performance suffers if recognition results are automatically assigned to every Strokes collection. Therefore results are not attached to a Strokes collection by default. To assign results to a Strokes collection, you must call the SetResultOnStrokes method. To return the recognition results for a Strokes collection, use the RecognitionResult property of the Strokes collection. After you assign results to a Strokes collection, you can then store the strokes in a CustomStrokes collection. These custom strokes, as well as the RecognitionResult, can be persisted and retrieved for later use.

In this example, synchronous recognition is handled in response to a user action such as clicking on a menu item or a button. First, the Strokes collection of a RecognizerContext object is assigned from the Strokes collection associated with an InkOverlay object, and checked for stroke count. If the Strokes collection contains at least one Stroke object, the recognition process begins with a call to the Recognize method. If recognition is successful, the SetResultOnStrokes method is called to attach the RecognizerContext object to its corresponding Strokes collection. Finally, the Strokes collection is saved as a named CustomStrokes collection. This saves the attached RecognitionResult as well.

// assign strokes collection from the collected strokes 
this.mRecognizerContext.Strokes = this.mInkOverlay.Ink.Strokes;
// check stroke count. Recognize() will throw exception if no strokes 
if (this.mRecognizerContext.Strokes.Count > 0)
{
    RecognitionStatus status;
    // perform the recognition
    RecognitionResult rResult = this.mRecognizerContext.Recognize(out status);
    // check status 
    if (RecognitionStatus.NoError == status)
    {
        // attach RecognitionResult to the Strokes collection
        rResult.SetResultOnStrokes();
        // save the strokes collection (with RecognitionResult attached) 
        try
        {
            mInkOverlay.Ink.CustomStrokes.Add("customCollectionName", rResult.Strokes);
        }
        catch (ArgumentException)
        {
            // this exception is raised when the named collection already exists
        }
    }
}

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft