
Over the last couple of days I was working on an internal demo and one
of the controls I built for that was a SpiderWebControl. It is a
Silverlight 4 custom control that allows you to draw a network graph. A
quick run down of the features is given below:
- Adding, removing, renaming of nodes
- Dragging of nodes
- CTRL + Drag to drag a subtree/branch
- CTRL + Drag on the canvas to pan around
- Selections and hovers using VSM
- Simple automatic layout with animations
The following video shows the control in action
Design choices
There were a few design decisions made while building this control that are worth highlighting:
- The top level control is called the
SpiderWebControland each node within that control is an instance of theSpiderWebItem. Ideally I would have derivedSpiderWebControlfromItemsControlif not for the extra level of control that I wanted for adding items to theItemsPanel. The node elements (boxes) and the connecting elements (lines) are inside two separate containers. The container that contains the boxes is overlaid on top of the container for lines. This achieves a nice effect of lines that seem to start from the edge of the box. Here you can see the connecting line and the box in different configurations

There is a private
DependencyPropertyon theSpiderWebItemcalledLinkedConnectorProperty. This is used to store the connector (Line) instance.- The
SpiderWebControlmakes use of theHierarchicalDataTemplatefrom the Silverlight Toolkit to expand nested levels (sub-branches)
Sidebar
Some of the ideas in the above list are discussed in more detail in my book “WPF Control Development Unleashed”.

Although the concepts are WPF specific, the ideas apply equally well to Silverlight.
Demo and code
I am sure you will agree that this post would be incomplete without a real demo and source code :–)