Multiple Link Data Types

I am trying to implement a second link type into my diagram, and am running into problems with having my link related tools creating the wrong link type and causing issues. I’m not sure if I’m properly defining my types for this to work best, I currently have:

MyModel : GraphLinksModel<GraphLinksModelNodeData, String, String, GraphLinksModelLinkData<String, String>>

PipeData : GraphLinksModelLinkData<String, String>

LinkData : GraphLinksModelLinkData<String, String>

In my tools when the link is created I believe it is creating a GraphLinksModelLinkData<String, String> link because that is what is being set in the Model… Is there any simple way to specify in each of the tools which data type to use for adding the link to the model?

Or maybe there is a simpler way to achieve my goal… I am trying to implement a 2nd LinkingTool that will only link from certain objects, and only needs to contain the base info… But my main link type which is used for everything else has a changeable color and arrowhead… so I’m assuming to have 2 separate data types I will need to specify in the tools somehow which one to use.


I don’t see why you have to use multiple data types as the link data type. You certainly can if you want to, but it isn’t required.

To make a smarter linking tool, override LinkingTool.IsValidLink and replace the Diagram.LinkingTool. You don’t have to have two separate linking tools either – you could parameterize the behavior based on some application state.

I can see how multiple tools aren’t necessary, and I guess I was using the same mindset with having multiple data types for nodes and applying that to links… But I’m not sure I follow how overriding IsValidLink will help as it should remain true where it was true before, the only thing that should change will be the type of link being created.

It looks like the new link is created in DoMouseUp, what is happening in the base method that I need to repeat to keep everything working as it currently is?


Oh, OK, I guess I misunderstood your situation.

Well, I think what you want is just a matter of overriding the 4-arg InsertLink method of your GraphLinksModel. By default it just creates an instance of the model’s LinkType and inserts it into the LinksSource collection by calling the 1-arg InsertLink method. But you can choose the data type you want to create and then construct and initialize it as you wish before calling the 1-arg InsertLink method.

Thanks, that is working great… The other problem I’m running into is changing the TemporaryLinkTemplate for the second link type (as the 2 link types have different routes). I’m guessing it’s something simple, but I’m drawing a blank.

For my Diagram I have:

<tools:CustomLinkingTool PortGravity=“15” TemporaryLinkTemplate="{StaticResource TemporaryPipeTemplate}" />

Which references a DataTemplate in the UserControl.Resources of the control containing my Diagram; which is also where my other template is that I would like to use. It doesn’t appear there is a TemplateDictionary set up for this as there is for regular links and nodes, so what is the best way to go about switching the TemporaryLinkTemplate?

I suppose you could override LinkingTool.DoActivate to call the base method and then modify the TemporaryLink, such as by setting its .Route.Routing or whatever properties you want.

If you really want to use a different template, you could remove the TemporaryLink from the diagram’s PartsModel, reset the TemporaryLink to an instance of what you want, and then add it to the Diagram.PartsModel.