ContextNode.Confirm 方法

设置确认类型,从而限制 InkAnalyzer 可更改哪些关于节点的内容。

命名空间:  System.Windows.Ink
程序集:  IAWinFX(在 IAWinFX.dll 中)

语法

声明
Public Sub Confirm ( _
    type As ConfirmationType _
)
用法
Dim instance As ContextNode
Dim type As ConfirmationType

instance.Confirm(type)
public void Confirm(
    ConfirmationType type
)
public:
void Confirm(
    ConfirmationType type
)
public void Confirm(
    ConfirmationType type
)
public function Confirm(
    type : ConfirmationType
)

参数

备注

调用 Confirm 后,在 InkAnalyzer 执行后续分析时,InkAnalyzer 不会更改与这些笔画关联的 ContextNode 对象。

例如,如果最终用户书写单词“to”,然后应用程序调用 Analyze,则 InkAnalyzer 将创建一个具有值“to”的 InkWord 节点。如果最终用户随后在“to”后面添加“me”作为一个整词,并且应用程序再次调用 Analyze,则 InkAnalyzer 可能创建一个具有值“tome”的 InkWord 节点。

但是,如果在首次调用 Analyze 之后,应用程序对具有“to”值 NodeTypeAndPropertiesInkWord 节点调用 Confirm,则添加“me”不会更改该节点。InkAnalyzer 将识别出“to me”对应的两个 InkWord 节点。

只能确认 InkWordInkDrawing 类型的 ContextNode 对象。如果尝试对非叶节点调用 Confirm,则会引发 InvalidOperationException

如果调用 InkAnalyzerRemoveStroke(Int32),而要移除的笔画与已确认的 ContextNode 对象相关,则 ContextNode 对象将自动设置为未确认。

如果 ContextNode 对象已确认,则 SetStrokes(array<Int32[]) 和 ReparentStroke(Int32, ContextNode) 会引发 InvalidOperationException。如果源节点或目标节点已确认,则 ReparentStroke(Int32, ContextNode) 会引发异常。

示例

在下面的示例中,用户可以指示已对哪些笔画进行了正确分析。此示例是 InkCanvas 对象 theInkCanvas 的 PreviewMouseUp 事件的事件处理程序。如果 CheckBox (confirmMode) 为选中状态,则用户单击一个单词即可对其进行确认(如果该节点已经确认,则关闭确认)。此示例使用 StrokeCollection.HitTest(Point)FindNodesOfType 查找适当的节点。在找到节点之后,调用 Confirm 以切换确认。最后,重新生成 TreeView 以显示哪些节点已经确认,并处理 PreviewMouseUp 事件。

Sub theInkCanvas_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)

    If Me.confirmMode.IsChecked Then

        ' Find the ink word nodes that correspond to those strokes
        Dim position As Point = e.GetPosition(theInkCanvas)
        Dim hitStrokes As StrokeCollection = theInkCanvas.Strokes.HitTest(position)

        Dim selectedNodes As ContextNodeCollection = _
            Me.theInkAnalyzer.FindNodesOfType(ContextNodeType.InkWord, _
            hitStrokes)

        ' Toggle the confirmation type on these nodes
        Dim selectedNode As ContextNode
        For Each selectedNode In selectedNodes
            If selectedNode.IsConfirmed(ConfirmationType.NodeTypeAndProperties) Then
                selectedNode.Confirm(ConfirmationType.None)
            Else
                selectedNode.Confirm(ConfirmationType.NodeTypeAndProperties)
            End If
        Next selectedNode

        ' Rebuild the TreeView to show which context nodes are confirmed.
        Me.BuildTree()

        ' Handle the MouseDown event to prevent the InkCanvas from
        ' selecting the stroke.
        e.Handled = True
    End If

End Sub 'theInkCanvas_PreviewMouseDown
void theInkCanvas_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    if ((bool)this.confirmMode.IsChecked)
    {
        // Find the ink word nodes that correspond to those strokes
        Point position = e.GetPosition(theInkCanvas);
        StrokeCollection hitStrokes = theInkCanvas.Strokes.HitTest(position);

        ContextNodeCollection selectedNodes =
            this.theInkAnalyzer.FindNodesOfType(ContextNodeType.InkWord,
            hitStrokes);

        // Toggle the confirmation type on these nodes
        foreach (ContextNode selectedNode in selectedNodes)
        {
            if (selectedNode.IsConfirmed(ConfirmationType.NodeTypeAndProperties))
            {
                selectedNode.Confirm(ConfirmationType.None);
            }
            else
            {
                selectedNode.Confirm(ConfirmationType.NodeTypeAndProperties);
            }
        }

        // Rebuild the TreeView to show which context nodes are confirmed.
        this.BuildTree();

        // Handle the MouseDown event to prevent the InkCanvas from
        // selecting the stroke.
        e.Handled = true;
    }
}

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

ContextNode 类

ContextNode 成员

System.Windows.Ink 命名空间

ContextNodeIsNodeTypeAndPropertiesConfirmed()