ContextNode.CreatePartiallyPopulatedSubNode Method

Creates a child ContextNode object that contains only the following information: Type, Id, and Location.

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

Syntax

'Declaration
Public Function CreatePartiallyPopulatedSubNode ( _
    type As Guid, _
    nodeId As Guid, _
    nodeLocation As AnalysisRegion _
) As ContextNode
'Usage
Dim instance As ContextNode
Dim type As Guid
Dim nodeId As Guid
Dim nodeLocation As AnalysisRegion
Dim returnValue As ContextNode

returnValue = instance.CreatePartiallyPopulatedSubNode(type, nodeId, nodeLocation)
public ContextNode CreatePartiallyPopulatedSubNode (
    Guid type,
    Guid nodeId,
    AnalysisRegion nodeLocation
)
public:
ContextNode^ CreatePartiallyPopulatedSubNode (
    Guid type, 
    Guid nodeId, 
    AnalysisRegion^ nodeLocation
)
public ContextNode CreatePartiallyPopulatedSubNode (
    Guid type, 
    Guid nodeId, 
    AnalysisRegion nodeLocation
)
public function CreatePartiallyPopulatedSubNode (
    type : Guid, 
    nodeId : Guid, 
    nodeLocation : AnalysisRegion
) : ContextNode
Not applicable.

Parameters

  • nodeId
    The identifier for the new node.
  • nodeLocation
    The location of the new node.

Return Value

A new ContextNode object that contains only information about Type, Id, and Location. This new node is a child of the ContextNode.

Remarks

This method is used for data proxy as a way to create a ContextNode object in the context node tree before all the information about it is available. The other information about it can be added at a later point.

Example

The following example is a method called CreatePartiallyPopulatedNode, from sample code that uses a System.Windows.Controls.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 by setting the System.Windows.FrameworkElement.Tag property of each TreeViewItem object to a DocumentNodeData object. The CreatePartiallyPopulatedNode method uses a TreeViewItem object and an InkAnalyzer object to create the partially populated node in the InkAnalyzer context node tree that corresponds to the TreeViewItem in the document model. In this sample, all the nodes are created as partially populated. They are then placed in a queue of nodes to later be fully populated with all the node data.

The method first obtains the node data from the System.Windows.FrameworkElement.Tag property of the TreeViewItem object that is passed in. Then it uses the Id to verify that the node is not currently in the context node tree. It then uses the tree view parent node to find the corresponding parent node in the InkAnalyzer. If the parent node does not yet exist in the context node tree, it is added using recursion. If the parent node does exist in the tree, it should be partially populated; if it were fully populated, it would already contain all its subnodes and there would be no need to add a new one. Therefore, the PartiallyPopulated property verifies that the parent node is partially populated, in which case it is added to a queue to later populate fully. If it is not partially populated, an exception is thrown. Finally, CreatePartiallyPopulatedSubNode is called on the parent node and the newly created node is added to the queue of nodes to be fully populated. The new ContextNode object is returned.

Private Function CreatePartiallyPopulatedNode(ByVal documentNode As TreeViewItem, ByVal theInkAnalyzer As InkAnalyzer) As ContextNode

    Dim nodeData As DocumentNodeData = documentNode.Tag '

    ' Check that the node does not already exist in the InkAnalyzer.
    If Nothing <> theInkAnalyzer.FindNode(nodeData.Id) Then
        Throw New ApplicationException("The node already exists in the InkAnalyzer.")
    End If

    ' Find the parent analyzer node.
    Dim parentNode As TreeViewItem = documentNode.Parent '

    If parentNode Is Nothing Then
        Throw New Exception("parentNode is not a TreeViewItem")
    End If

    Dim parentNodeData As DocumentNodeData = parentNode.Tag
    Dim analyzerParentNode As ContextNode = theInkAnalyzer.FindNode(parentNodeData.Id)

    If Nothing = analyzerParentNode Then
        ' The parent analyzer node does not exist yet. Create one.
        analyzerParentNode = Me.CreatePartiallyPopulatedNode(parentNode, theInkAnalyzer)
    ElseIf analyzerParentNode.PartiallyPopulated Then
        ' The parent analyzer node exists and is partially populated. Add it
        ' to the stack of nodes to fully populate.
        Me.QueueNodeToPopulate(analyzerParentNode)
    Else
        ' The parent analyzer node exists and is fully populated. This
        ' should not happen.
        Throw New ApplicationException("The parent analyzer node is fully populated.")
    End If

    ' Create the partially populated node under its parent analyzer node.
    Dim analyzerNode As ContextNode = analyzerParentNode.CreatePartiallyPopulatedSubNode(nodeData.Type, nodeData.Id, nodeData.Location)

    ' Add the new node to the stack of nodes to fully populate.
    Me.QueueNodeToPopulate(analyzerNode)

    Return analyzerNode

End Function 'CreatePartiallyPopulatedNode
private ContextNode CreatePartiallyPopulatedNode(
    TreeViewItem documentNode, InkAnalyzer theInkAnalyzer)
{
    DocumentNodeData nodeData = documentNode.Tag as DocumentNodeData;

    // Check that the node does not already exist in the InkAnalyzer.
    if (null != theInkAnalyzer.FindNode(nodeData.Id))
    {
        throw new ApplicationException(
            "The node already exists in the InkAnalyzer.");
    }

    // Find the parent analyzer node.
    TreeViewItem parentNode = documentNode.Parent as TreeViewItem;

    if (parentNode == null)
    {
        throw new Exception("parentNode is not a TreeViewItem");
    }

    DocumentNodeData parentNodeData =
        parentNode.Tag as DocumentNodeData;
    ContextNode analyzerParentNode =
        theInkAnalyzer.FindNode(parentNodeData.Id);
    if (null == analyzerParentNode)
    {
        // The parent analyzer node does not exist yet. Create one.
        analyzerParentNode =
            this.CreatePartiallyPopulatedNode(
                parentNode, theInkAnalyzer);
    }
    else if (analyzerParentNode.PartiallyPopulated)
    {
        // The parent analyzer node exists and is partially populated. Add it
        // to the stack of nodes to fully populate.
        this.QueueNodeToPopulate(analyzerParentNode);
    }
    else
    {
        // The parent analyzer node exists and is fully populated. This
        // should not happen.
        throw new ApplicationException(
            "The parent analyzer node is fully populated.");
    }

    // Create the partially populated node under its parent analyzer node.
    ContextNode analyzerNode =
        analyzerParentNode.CreatePartiallyPopulatedSubNode(
            nodeData.Type, nodeData.Id, nodeData.Location);

    // Add the new node to the stack of nodes to fully populate.
    this.QueueNodeToPopulate(analyzerNode);

    return analyzerNode;
}

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
ContextNode.PartiallyPopulated