Stencils using GoXam Diagram

Dear Admin,



Is there an example where I can design and use stencils? By ‘stencils’, I mean, grouping of icons like split state, process state etc. and if I use the stencil the entire diagram would placed on the canvas.



We don’t have such an example at this time. But there are a lot of ways of implementing such functionality, depending on the particular features you want.

First, please realize that the Palette.NodeTemplate need not be the same as the Diagram.NodeTemplate that you use in the diagram that the user is creating. It’s common for the Palette DataTemplates to be relatively simple. Sometimes you can just use a TextBlock.

Second, the Palette’s Model should be of the same type as the Diagram’s Model. If the models are incompatible, and particularly if the model data is incompatible, the standard drag-and-drop behavior won’t work and you’ll need to implement your own.

Third, a relatively easy solution is to implement a Diagram.ExternalObjectsDropped event handler on your main Diagram. When it gets invoked, the Diagram.SelectedParts collection holds all of the newly created Parts. Typically that will be just a single Node that the user dropped.

But in the ExternalObjectsDropped event handler you can add as many more Nodes and Links as you want. As with any other dynamic creation of parts, you should do so by adding data to the Diagram.Model. (In this case you don’t need to start and commit a transaction because the DraggingTool already has one going when the ExternalObjectsDropped event occurs.)

You probably will want to look at the selected Node(s) to decide where to create your additional parts.

You don’t have to keep the Node that was dropped – if you don’t want it, just remove that data from the model.

There is a very simple example of a Diagram.ExternalObjectsDropped event handler in the Planogram sample. It just resizes the dropped nodes to make sure they are multiples of the cell size.