On Link creation update LinkNodeData property

Scenario: After user creates a link I would like to change the link visually based on the To and From Node? What event can I listen for newly created link and check it’s from and to source type.

What are my options? Currently I have one LinkTemplate and use a converter to show and hide different Polygons and Path.
Thank you,


The user-drawn linking event is Diagram.LinkDrawn. (There is also Diagram.LinkRelinked, which may be of interest to you for the same reason.)

At that time you can change some data property, depending on data-binding to update the appearance of the link.

Or you could change the DataTemplate being used by changing the GraphLinksModelLinkData.Category of the link data.

Remember to wrap all your data and/or model changes in a transaction.

By the way, it’s probably more efficient in construction time and space to use separate DataTemplates when there are significant differences in appearances. If you are making some elements visible and others collapsed based on a converter, it means that all of the elements were created when the Part was added to the Diagram.

By using two (or several) different DataTemplates, each one can be a lot simpler. That’s both clearer to those who need to maintain the XAML and faster to apply when building the part. The downside is that changing templates (by changing the data Category) does discard the Part’s old visual tree and rebuild according to the new template.

Hi Walter,

Thank you for explaining why using multiple DataTemplates is a better approach!


I use a GraphModel and I have two LinkTemplates in my LinkTemplateDictionary. How can I change the used Template of the Link (after the Link is added to the diagram)? Just changing the Category does not work.

Any suggestions?



PartManager.FindCategoryForLink is responsible for finding the category name for a link. You could override this method to return what you want, given the link data.

For a GraphLinksModel, the link data is just the link data. But for a GraphModel, where there is no separate link data for which one could set a Category property, the link data is actually an instance of PartManager.VirtualLinkData, which gives you access to the node data at both the “from” and the “to” ends.

You can read the documentation for PartManager.FindCategoryForLink to get a description of what it does by default.

Anyway, once you have that method doing what you want at the times you want, you just need to remove the Link and then re-create it in the Diagram. You can do that by calling PartManager.RemoveLinkForData and then calling PartManager.AddLinkForData. Because a GraphModel has no other way of identifying a link, you’ll need to call the versions of those methods that take the “fromnodedata” and the “tonodedata” as arguments.