The Virtualizing sample demonstrates one way to support many thousands of nodes and links. The principal technique is the customization of the PartManager to only create Nodes and Links when they are visible in the DiagramPanel, and to delete them otherwise.

This sample creates 9999 nodes and 9998 links. The scrolling and zooming performance is a bit sluggish (worse in Silverlight than in WPF), but responsiveness remains good for operations on individual nodes and links. You will find it more responsive when zoomed in so that there are fewer nodes and links that are visible at one time. Without virtualization just the creation of so many Nodes and Links would result in a very long and unavoidable start-up time.

This sample requires all node data to have a location before they have been realized as Nodes in the Diagram. Because all of the regular layouts, such as TreeLayout and LayeredDigraphLayout, depend on knowing the actual size of each Node in order to perform a reasonable positioning of the nodes, this sample requires that there not be any layout given as the Diagram.Layout. Many of the regular layouts also route the links as part of the layout process. This would also require that the actual Links be present so that their Routes can be modified.

Instead of a regular TreeLayout, this defines a VirtualizingTreeLayout that operates directly on the node and link data of the model rather than Nodes and Links of the Diagram. It uses custom VirtualizingTreeVertex and VirtualizingTreeEdge classes that know about this application's NodeData and LinkData data classes. The layout assigns the NodeData.Location property rather than the Node.Location property as standard layouts would do. However, it does not support custom routing.

The standard Diagram.Panel is replaced with an instance of the custom VirtualizingDiagramPanel class. The use of the custom VirtualizingDiagramPanel class requires customizing the diagram's Template. The supplied ControlTemplate is exactly like the default one that you can see in the Generic.XAML file in the docs subdirectory of the GoXam installation, except for the replacement of the standard DiagramPanel with the custom VirtualizingDiagramPanel.

The standard Diagram.PartManager is replaced with an instance of the custom VirtualizingPartManager class.

Both the VirtualizingPartManager and the VirtualizingDiagramPanel make all of their geometric calculations based on the node data and the relationships provided by the model. They must not depend on the actual Node.Bounds, because the whole point of virtualization is to avoid creating FrameworkElements such as Nodes.

If you want to use the code of this sample, you will need to adapt the ComputeNodeBounds method to return reasonably accurate values for your particular node data, as if they had been realized with the actual DataTemplates that your application uses. Remember also that the Node.Location in your application might not be the point at the top-left corner of the Bounds for that node.

If you want to use a different kind of layout, you will need to customize that layout in a manner similar to how the TreeLayout was modified to support virtualization.