Highlight different element when linking?

I’m using the default LinkingTool in WPF. I’ve set Node.LinkableFrom and Node.LinkableTo on an element deep within my node template. When the linking tool runs, it surrounds that element with a purplish box to indicate the link end points. I’d like the draw the purple box around a different (higher) element in the node template. How can I do this? I looked for an attached property similar to Part.SelectionElementName, but didn’t find anything.

The only Node attached properties I’m using in my template are Location, LocationElementName, LocationSpot, LinkableFrom, and LinkableTo.

Just override LinkingTool.CopyPortProperties to do whatever you want.
Here’s a cleaned-up version of the standard definition:

protected virtual void CopyPortProperties(Node realnode, FrameworkElement realport, Node tempnode, FrameworkElement tempport, bool toend) { if (realnode == null || realport == null || tempnode == null || tempport == null) return; Size portsz = new Size(realport.ActualWidth, realport.ActualHeight); tempport.Width = portsz.Width; tempport.Height = portsz.Height; if (toend) { Node.SetToSpot(tempport, Node.GetToSpot(realport)); Node.SetToEndSegmentLength(tempport, Node.GetToEndSegmentLength(realport)); } else { Node.SetFromSpot(tempport, Node.GetFromSpot(realport)); Node.SetFromEndSegmentLength(tempport, Node.GetFromEndSegmentLength(realport)); } tempnode.LocationSpot = Spot.Center; tempnode.Location = realnode.GetElementPoint(realport, Spot.Center); tempnode.SetAngle(tempport, realnode.GetAngle(realport)); }
You might want to do the same to the RelinkingTool, if that applies to your app.

Which one is the purple box: the temporary port or the temporary node? I’m guessing the node?

You can specify the template for those parts by setting LinkingBaseTool.TemporaryNodeTemplate.
(And you can set TemporaryLinkTemplate too.)

You can see the default templates in the GenericWPF.xaml file that is in the docs subdirectory of the installation.

Sorry, I’m not being clear: I’m happy with the appearance of the TemporaryNodeTemplate, but I’d like to change which element of my node template it surrounds/adorns. How would I indicate that different element? Specifically, I want the temporary node to surround the element indicated by the Part.SelectionElementName attached property.

I haven’t tried this, but I would just pretend the “realport” is the node’s SelectionElement:

protected override void CopyPortProperties(Node realnode, FrameworkElement realport, Node tempnode, FrameworkElement tempport, bool toend) { if (realnode == null || realport == null || tempnode == null || tempport == null) return; realport = realnode.SelectionElement; base.CopyPortProperties(realnode, realport, tempnode, tempport, toend); }

Thanks, that worked perfectly.