ContextNode.SetStrokes Method

Sets the specified strokes on a ContextNode object.

Namespace: System.Windows.Ink
Assembly: IAWinFX (in iawinfx.dll)

Syntax

'Declaration
Public Sub SetStrokes ( _
    strokes As StrokeCollection _
)
'Usage
Dim instance As ContextNode
Dim strokes As StrokeCollection

instance.SetStrokes(strokes)
public void SetStrokes (
    StrokeCollection strokes
)
public:
void SetStrokes (
    StrokeCollection^ strokes
)
public void SetStrokes (
    StrokeCollection strokes
)
public function SetStrokes (
    strokes : StrokeCollection
)
Not applicable.

Parameters

Remarks

This method does not update the DirtyRegion.

If any of the specified strokes in the stroke collection are already set on the InkAnalyzer, an ArgumentException is thrown.

Example

The following example is a method called PopulateNode, from sample code that uses a TreeView as a document model to show how data proxy can be used to store and load a context node tree for an InkAnalyzer. The DocumentNodeData class stores the ContextNode data in the document model when the Tag property of each TreeViewItem object is set to a DocumentNodeData object.

The PopulateNode method fully populates a ContextNode object by adding strokes, property data, annotation type, child nodes, and links from an InkAnalyzer object. It uses SetStrokes to add the strokes. The data comes from the DocumentNodeData object that is obtained from the corresponding TreeViewItem.

  • this[analyzerNode.Id] is an indexer on the document model class that maps a Guid to a TreeViewItem. (Me(analyzerNode.Id) in VB.NET)

  • AddLinksToAnalyer is a method on the document model class that adds links to the ContextNode.

After the node is fully populated, the PartiallyPopulated property is set to false.

Sub PopulateNode(ByVal analyzerNode As ContextNode, ByVal theInkAnalyzer As InkAnalyzer)  Implements IDocumentModel.PopulateNode

    System.Diagnostics.Debug.WriteLine(String.Format("IDocumentModel.PopulateNode: populate {0} {1}.", analyzerNode.ToString(), GetRecognizedString(analyzerNode)))
    System.Diagnostics.Debug.Indent()
    
    ' Get the document node associated with the analyzer node.
    Dim documentNode As TreeViewItem = Me(analyzerNode.Id)
    If documentNode Is Nothing Then
        Throw New ApplicationException("The requested node does not exist in the document model.")
    End If
    
    ' Get the data associated with the node.
    Dim nodeData As DocumentNodeData = documentNode.Tag '

    ' Copy any application specific data associated with the node to the
    ' partially populated ContextNode.
    For Each identifier As Guid In nodeData.GetPropertyDataIds()
        analyzerNode.AddPropertyData(identifier, nodeData.GetPropertyData(identifier))
    Next identifier
    
    ' Check if the partially populated ContextNode is an ink leaf node.
    If nodeData.IsInkLeafNode Then
        ' Add the strokes to the context node.
        analyzerNode.SetStrokes(nodeData.Strokes)
    Else
        ' Add each child subnode as a partially populated ContextNode.
        Dim documentSubNode As TreeViewItem
        For Each documentSubNode In  documentNode.Items
            ' Get the DocumentNode data for the 
            Dim subNodeData As DocumentNodeData = documentSubNode.Tag '

            If analyzerNode.SubNodes.IndexOf(nodeData.Id) <> -1 Then
                analyzerNode.CreatePartiallyPopulatedSubNode( _
                subNodeData.Type, subNodeData.Id, subNodeData.Location)
            End If
        Next documentSubNode
    End If
    
    ' Add links to the ContextNode.
    Me.AddLinksToAnalyzer(documentNode, analyzerNode, theInkAnalyzer)
    
    ' Update the partially populated flag.
    analyzerNode.PartiallyPopulated = False
    
    System.Diagnostics.Debug.Unindent()

End Sub 'IDocumentModel.PopulateNode
void IDocumentModel.PopulateNode(
    ContextNode analyzerNode,
    InkAnalyzer theInkAnalyzer)
{
    System.Diagnostics.Debug.WriteLine(string.Format(
        "IDocumentModel.PopulateNode: populate {0} {1}.",
        analyzerNode.ToString(), GetRecognizedString(analyzerNode)));
    System.Diagnostics.Debug.Indent();

    // Get the document node associated with the analyzer node.
    TreeViewItem documentNode = this[analyzerNode.Id];
    if (null == documentNode)
    {
        throw new ApplicationException(
            "The requested node does not exist in the document model.");
    }

    // Get the data associated with the node.
    DocumentNodeData nodeData = documentNode.Tag as DocumentNodeData;

    // Copy any application specific data associated with the node to the
    // partially populated ContextNode.
    foreach (Guid identifier in nodeData.GetPropertyDataIds())
    {
        analyzerNode.AddPropertyData(
            identifier, nodeData.GetPropertyData(identifier));
    }

    // Check if the partially populated ContextNode is an ink leaf node.
    if (nodeData.IsInkLeafNode)
    {
        // Add the strokes to the context node.
        analyzerNode.SetStrokes(nodeData.Strokes);
    }
    else
    {
        // Add each child subnode as a partially populated ContextNode.
        foreach (TreeViewItem documentSubNode in documentNode.Items)
        {
            // Get the DocumentNode data for the 
            DocumentNodeData subNodeData = documentSubNode.Tag as DocumentNodeData;

            if (analyzerNode.SubNodes.IndexOf(nodeData.Id) != -1)
            {
                analyzerNode.CreatePartiallyPopulatedSubNode(
                    subNodeData.Type, subNodeData.Id, subNodeData.Location);
            }
        }
    }

    // Add links to the ContextNode.
    this.AddLinksToAnalyzer(documentNode, analyzerNode, theInkAnalyzer);

    // Update the partially populated flag.
    analyzerNode.PartiallyPopulated = false;

    System.Diagnostics.Debug.Unindent();
}

Platforms

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

ContextNode Class
ContextNode Members
System.Windows.Ink Namespace