Adding Connections to the Toolbox

We have seen that users can automatically create connections by dragging the mouse from one connection point to another, but that this creates a ‘default’ line. We need to give users a way of creating other line types, such as routed lines or lines with arrows at their ends. This is most easily done by adding connection tools to our existing toolbox.

WPF Diagrams defines a number of built-in line types, and you can specify these as toolbox entries by creating a DiagramConnectionTool and setting the ConnectionTool.LineType attached property:

CopyXML
<ms:DiagramToolBoxGroup Header="Lines">
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="Straight" />
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="StraightArrow" />
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="StraightDoubleArrow" />
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="Elbow" />
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="ElbowArrow" />
  <ms:DiagramConnectionTool ms:ConnectionTool.LineType="ElbowDoubleArrow" />
</ms:DiagramToolBoxGroup>

Now the user can click a line type in the toolbox and drag between two connection points, and the resulting line will have the appropriate routing and arrows.

Next: Loading and Saving.