ContextNode Class
Represents a node in a tree of objects that are created as part of ink analysis.
Assembly: IAWinFX (in IAWinFX.dll)
After an InkAnalyzer performs an ink analysis, it presents the results as a tree of ContextNode objects. The [T:System.Windows.Ink.RootNode is located at the top of the tree]; the tree presents smaller and smaller collections of strokes further down the tree. These nodes can be groups of words (such as paragraphs or lines), analyzed ink (such as words or drawings), or a variety of other types. (See the ContextNodeType class for a full list.)
You can manually add nodes, such as AnalysisHintNode, ImageNode and TextWordNode objects, to the InkAnalyzer.
In cases of corrupt input, this method throws a ArgumentException exception.
This example takes an InkAnalyzer named theInkAnalyzer, and uses its ContextNode tree to fill a [System.Windows.Controls.TreeView] named theTreeView. When a node belonging to a tree view is selected, its associated strokes are set to appear in red. The [System.Windows.FrameworkElement.Tag] property is used to map between tree nodes and the context nodes that they represent.
Private Sub BuildTree() ' Remove the old nodes from the TreeView and add the current results. Me.theResultsTreeView.Items.Clear() Dim rootNode As New TreeViewItem() rootNode.Tag = Me.theInkAnalyzer.RootNode rootNode.Header = theInkAnalyzer.RootNode.ToString() Me.theResultsTreeView.Items.Add(rootNode) WalkTree(Me.theInkAnalyzer.RootNode, rootNode) End Sub 'BuildTree Private Shared Sub WalkTree(ByVal parentContextNode As ContextNode, ByVal parentTreeNode As TreeViewItem) parentTreeNode.IsExpanded = True For Each theContextSubnode As ContextNode In parentContextNode.SubNodes Dim newTreeNode As New TreeViewItem() newTreeNode.Header = theContextSubnode.ToString() If TypeOf theContextSubnode Is InkWordNode Then newTreeNode.Header += ": " + CType(theContextSubnode, InkWordNode).GetRecognizedString() ElseIf TypeOf theContextSubnode Is InkDrawingNode Then newTreeNode.Header += ": " + CType(theContextSubnode, InkDrawingNode).GetShapeName() End If ' If the context node is confirmed, add a note to the ' tree view item. If (theContextSubnode.IsConfirmed(ConfirmationType.NodeTypeAndProperties)) Then newTreeNode.Header += " Confirmed." End If ' Add the context node as a tag of the tree view item and ' add the new tree view item to the parent node. newTreeNode.Tag = theContextSubnode parentTreeNode.Items.Add(newTreeNode) WalkTree(theContextSubnode, newTreeNode) Next theContextSubnode End Sub 'WalkTree Sub theResultsTreeView_SelectedItemChanged(ByVal sender As Object, _ ByVal e As RoutedPropertyChangedEventArgs(Of Object)) Dim selectedTreeViewItem As TreeViewItem = e.NewValue ' If selectedTreeViewItem Is Nothing Then Return End If ' Get the context node Dim selectedNode As ContextNode = CType(selectedTreeViewItem.Tag, ContextNode) MarkNodeAsRed(selectedNode) timeStampLabel.Content = "" ' Show selected results If Not (selectedNode Is Nothing) Then If selectedNode.Type = ContextNodeType.WritingRegion Then Dim writingRegion As WritingRegionNode = CType(selectedNode, WritingRegionNode) selectedResultsTextBox.Text = writingRegion.GetRecognizedString() ElseIf selectedNode.Type = ContextNodeType.Paragraph Then Dim paragraph As ParagraphNode = CType(selectedNode, ParagraphNode) selectedResultsTextBox.Text = paragraph.GetRecognizedString() ElseIf selectedNode.Type = ContextNodeType.Line Then Dim line As LineNode = CType(selectedNode, LineNode) selectedResultsTextBox.Text = line.GetRecognizedString() ElseIf selectedNode.Type = ContextNodeType.InkWord Then Dim inkWord As InkWordNode = CType(selectedNode, InkWordNode) Dim parentNode As ContextNode = inkWord.ParentNode If TypeOf parentNode Is LineNode Then Dim parentLine As LineNode = CType(parentNode, LineNode) ' Put parent line's recognized string into the text box selectedResultsTextBox.Text = parentLine.GetRecognizedString() ' Select the text that corresponds to the ink word Dim subNodes As New ContextNodeCollection(theInkAnalyzer) subNodes.Add(inkWord) Dim start As Integer Dim length As Integer parentLine.GetTextRangeFromNodes(subNodes, start, length) If start >= 0 AndAlso length > 0 Then selectedResultsTextBox.Select(start, length) End If End If ElseIf selectedNode.Type = ContextNodeType.InkDrawing Then Dim drawingNode As InkDrawingNode = CType(selectedNode, InkDrawingNode) selectedResultsTextBox.Text = drawingNode.GetShapeName() ElseIf selectedNode.Type = ContextNodeType.InkBullet Then Dim bulletNode As InkBulletNode = CType(selectedNode, InkBulletNode) selectedResultsTextBox.Text = bulletNode.GetRecognizedString() ElseIf selectedNode.Type = ContextNodeType.CustomRecognizer Then Dim customRecognizer As CustomRecognizerNode = CType(selectedNode, CustomRecognizerNode) selectedResultsTextBox.Text = customRecognizer.GetRecognizedString() ElseIf selectedNode.Type = ContextNodeType.Object Then Dim selectedObject As ObjectNode = CType(selectedNode, ObjectNode) selectedResultsTextBox.Text = selectedObject.GetRecognizedString() Else selectedResultsTextBox.Text = "" End If If TypeOf selectedNode Is InkWordNode Then Dim inkWord As InkWordNode = CType(selectedNode, InkWordNode) ' Show the time stamp If inkWord.ContainsPropertyData(Me.timeStampGuid) Then Dim timeStamp As DateTime = CType(inkWord.GetPropertyData(Me.timeStampGuid), DateTime) timeStampLabel.Content = timeStamp.ToShortTimeString() End If ' Snippet to demonstrate GetPropertyDataIds Dim propertyDataIds As Guid() = inkWord.GetPropertyDataIds() ' Snippets to demonstrate loading and saving Dim data As Byte() = inkWord.SavePropertiesData() If Not inkWord.LoadPropertiesData(data) Then MessageBox.Show("Cannot load property data") End If End If End If PopulateLinksList(selectedNode) Me.currentNode = selectedNode End Sub Private Sub PopulateLinksList(ByVal selectedNode As ContextNode) linksListBox.Items.Clear() If selectedNode Is Nothing Then Return End If Dim link As ContextLink For Each link In selectedNode.Links linksListBox.Items.Add(link.SourceNode.ToString() + ", " & _ link.DestinationNode.ToString() & ": " & _ link.LinkDirection.ToString()) Next End Sub Sub MarkNodeAsRed(ByVal selectedNode As ContextNode) ' Set all node strokes to black, but this one to red Dim stroke As Stroke For Each stroke In Me.theInkCanvas.Strokes If Not (selectedNode Is Nothing) AndAlso selectedNode.Strokes.Contains(stroke) Then stroke.DrawingAttributes.Color = Colors.Red Else stroke.DrawingAttributes.Color = Me.theInkCanvas.DefaultDrawingAttributes.Color End If Next stroke End Sub 'theResultsTreeView_SelectedItemChanged
System.Windows.Ink.ContextNode
System.Windows.Ink.AnalysisHintNode
System.Windows.Ink.CustomRecognizerNode
System.Windows.Ink.ImageNode
System.Windows.Ink.InkBulletNode
System.Windows.Ink.InkDrawingNode
System.Windows.Ink.InkWordNode
System.Windows.Ink.LineNode
System.Windows.Ink.ObjectNode
System.Windows.Ink.ParagraphNode
System.Windows.Ink.RootNode
System.Windows.Ink.TextWordNode
System.Windows.Ink.UnclassifiedInkNode
System.Windows.Ink.WritingRegionNode
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
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.