ContextNode.CreatePartiallyPopulatedSubNode 方法
创建一个只包含以下信息的子 ContextNode 对象:Type、Id 和 Location。
命名空间: System.Windows.Ink
程序集: IAWinFX(在 IAWinFX.dll 中)
语法
声明
Public Function CreatePartiallyPopulatedSubNode ( _
type As Guid, _
nodeId As Guid, _
nodeLocation As AnalysisRegion _
) As ContextNode
用法
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
参数
- type
类型:System.Guid
所创建的 ContextNode 对象的类型。
- nodeId
类型:System.Guid
新节点的标识符。
- nodeLocation
类型:System.Windows.Ink.AnalysisRegion
新节点的位置。
返回值
类型:System.Windows.Ink.ContextNode
一个只包含有关 Type、Id 和 Location 的信息的新 ContextNode 对象。此新节点是 ContextNode 的子级。
备注
此方法用于数据代理,作为在有关某 ContextNode 对象的所有信息可用之前在上下文节点树中创建该对象的一种途径。可在以后添加有关该对象的其他信息。
示例
下面的示例是一个名为 CreatePartiallyPopulatedNode 的方法,该方法将 [System.Windows.Controls.TreeView] 作为一个文档模型来演示如何使用数据代理存储和加载 InkAnalyzer 的上下文节点树。通过将每个 TreeViewItem 对象的 [System.Windows.FrameworkElement.Tag] 属性都设置为一个 DocumentNodeData 对象,DocumentNodeData 类将 ContextNode 数据存储在该文档模型中。CreatePartiallyPopulatedNode 方法使用 TreeViewItem 对象和 InkAnalyzer 对象,在 InkAnalyzer 上下文节点树中创建与文档模型中的 TreeViewItem 相对应的部分填充的节点。在此示例中,所有节点都是以部分填充的方式创建的。然后,这些节点被放入节点队列,供以后用节点数据完全填充。
该方法从传入的 TreeViewItem 对象的 [System.Windows.FrameworkElement.Tag] 属性中获取节点数据。然后,使用 Id 验证节点当前是否不在上下文节点树中:使用树视图父节点在 InkAnalyzer 中查找相应的父节点。如果父节点尚未存在于上下文节点树中,则使用递归添加该父节点。如果父节点存在于树中,则应是部分填充的;如果父节点已完全填充,则该节点应当已经包含其所有子节点,因而无需添加新的子节点。因此,PartiallyPopulated 属性验证父节点是否为部分填充的;如果是部分填充的,则将该节点添加到队列中,供以后完全填充。如果该节点不是部分填充的,则引发异常。最后,对父节点调用 [M:System.Windows.Ink.ContextNode.CreatePartiallyPopulatedSubNode (System.Windows.Ink.ContextNodeType,System.Guid,System.Windows.Ink.AnalysisRegion)],并将新创建的节点添加到节点队列中以供完全填充。返回新的 ContextNode 对象。有关数据代理的更多信息,请参见Data Proxy with Ink Analysis。
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;
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0