RecognizerContextRecognitionEventArgs.CustomData 属性

获取包含识别结果的自定义数据的对象。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public ReadOnly Property CustomData As Object
用法
Dim instance As RecognizerContextRecognitionEventArgs
Dim value As Object

value = instance.CustomData
public Object CustomData { get; }
public:
property Object^ CustomData {
    Object^ get ();
}
/** @property */
public Object get_CustomData()
public function get CustomData () : Object

属性值

类型:System.Object
包含识别结果的自定义数据的对象。

备注

调用 RecognizerContext 对象的 BackgroundRecognizeWithAlternates 方法时,可以提供自定义数据。当 RecognizerContext 对象引发 RecognitionWithAlternates 事件时,自定义数据在 RecognizerContextRecognitionWithAlternatesEventArgs 对象的 CustomData 属性中可用。

示例

此示例自动识别在 InkOverlay 对象中创建的每个笔画,并显示识别结果。

在激发 Stroke 事件(对用户完成笔画做出的响应)时,会将新创建的笔画添加到 RecognizerContext 对象的 Strokes 集合中,并调用 BackgroundRecognize 方法,调用时将当前时间传递给 customData 参数。

Private Sub mInkOverlay_Stroke4(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    ' in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition()
    ' add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke)
    mRecognizerContext.BackgroundRecognize(DateTime.Now)
End Sub
private void mInkOverlay_Stroke4(object sender, InkCollectorStrokeEventArgs e)
{
    // in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition();
    // add the stroke, and start recognition, passing current time
    mRecognizerContext.Strokes.Add(e.Stroke);
    mRecognizerContext.BackgroundRecognize(DateTime.Now);
}

完成后台识别时将激发 Recognition 事件。在处理此事件的过程中,会将识别结果放入一个列表框。此外,还将从 RecognizerContextRecognitionEventArgs 对象的 CustomData 属性检索识别的起始时间,并使用该时间计算识别所需的总时间。

' event fires when recognition results (without alternates) are ready
Private Sub RecognizerContext_Recognition(ByVal sender As Object, _
            ByVal e As RecognizerContextRecognitionEventArgs)
    ' when updating a control, must use Invoke() since controls are
    ' not thread safe and recognition occurs on a different thread
    If Me.InvokeRequired Then
        ' recursively call this method via Invoke()
        Me.Invoke( _
            New RecognizerContextRecognitionEventHandler(AddressOf RecognizerContext_Recognition), _
            New Object() {sender, e} _
        )
        Return
    End If
    If RecognitionStatus.NoError = e.RecognitionStatus Then
        listBoxRecognitionResults.Items.Add(e.Text)
        ' get the custom data and calculate elapsed time
        Dim startTime As DateTime = DirectCast(e.CustomData, DateTime)
        Dim endTime As DateTime = DateTime.Now
        Dim span As TimeSpan = New TimeSpan(endTime.Ticks - startTime.Ticks)
        ' display the number of seconds for this recognition to finish
        listBoxRecognitionResults.Items.Add(span.TotalSeconds.ToString())
    End If
End Sub
// event fires when recognition results (without alternates) are ready
private void RecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
    // when updating a control, must use Invoke() since controls are
    // not thread safe and recognition occurs on a different thread
    if (this.InvokeRequired)
    {
        // recursively call this method via Invoke()
        this.Invoke(
            new RecognizerContextRecognitionEventHandler(RecognizerContext_Recognition),
            new object[] { sender, e }
            );
        return;
    }

    if (RecognitionStatus.NoError == e.RecognitionStatus)
    {
        listBoxRecognitionResults.Items.Add(e.Text);
        // get the custom data and calculate elapsed time
        DateTime startTime = (DateTime)e.CustomData;
        DateTime endTime = DateTime.Now;
        TimeSpan span = new TimeSpan(endTime.Ticks - startTime.Ticks);
        // display the number of seconds for this recognition to finish
        listBoxRecognitionResults.Items.Add(span.TotalSeconds.ToString());
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RecognizerContextRecognitionEventArgs 类

RecognizerContextRecognitionEventArgs 成员

Microsoft.Ink 命名空间

RecognizerContext

RecognizerContext.Recognition

RecognizerContext.BackgroundRecognize