Part Location and Adornment Location

Hi

I’ve been going through the help documentation and I see that Part has an Adornments property. I’ve also looked at the MakeAdornment and SetAdornment methods for adding adornments to a part. I couldn’t find much documentation on how to properly use adornments so I had to use Reflector to try and understand how to add and use adornments.

The problem I’m having is that I can successfully add an adornment to a part but if the part is moved the adornment’s location is not updated accordingly.

This is the initial state of the part with the adornment added:

And here is what it looks like after I’ve moved the part:

How can I get the adornment’s location to remain relative to the part’s location?
From looking at Reflector I can’t see anything specific happening in terms of the adornment’s location other than setting the adornment’s initial location.

Here’s the code I’m using to add the adornment:

var part = diagram.Diagram.PartManager.FindNodeForData(node, diagram.Diagram.Model);

var x = part.MakeAdornment(part.SelectionElement, (DataTemplate)Sys.Application.Current.Resources[“TestA”]);

x.Category = “TestA”;
x.LocationSpot = Northwoods.GoXam.Spot.BottomRight;
x.Location = part.GetElementPoint(part.SelectionElement, Northwoods.GoXam.Spot.Center);

part.SetAdornment(“TestA”, x);

Thanks
Justin

What is documented is how Adornments are used to provide additional temporary Parts for selected Parts, either to show selection or to help implement tool functionality. So you can read about Part.SelectionAdornmentTemplate, Part.ResizeAdornmentTemplate, DiagramTool.UpdateAdornments, et al.

What are you trying to achieve? If you are just looking to extend the visual tree of the Node, you can do that without using any GoXam functionality. You can even use Adorners.

Hi Walter

Our application allows the user to apply certain report filters to the diagram. Depending on the report filters chosen and the results of those filters, each node in the diagram could have certain adornments applied to it. We can’t simply use a DataTemplateDictionary to cater for the different node appearances as there are different types of adorners that could be applied simultaneously to a single node.

I can achieve the behaviour I need by making use of my own Adorner objects and add them as necessary to the relevant Node by calling the SetAdorner method. Why I’m trying to figure out is how to get my adorners to move with the Node whenever the Node is moved around in the diagram. For example, the builtin Selection Adorner or Resize Adorner move with the Node when the Node is moved around in the diagram. As you can see in the images of my first post, when I move the Node that has my own Adorner object added to it, the Adorner does not move with the Node. I used Reflector to see how the Part class adds the Selection Adorner to itself whenever the Part is selected. I wrote my code based on that code expecting my adorner to behave in a similar way (ie. to move with the Node).

I can get the adorner to move with the Node if I add the following to the rool element of my Adorner’s DataTemplate:
go:Node.Location={Binding Part.AdornedPart.Data.Location, Mode=TwoWay}

But if I look at the default DataTemplate for the Resize adorner, it has no such declaration (go:Node.Location …) in it’s template definition:

go:SpotPanel








</go:SpotPanel>

and yet the Resize adorner moves along with the Node.

So my question is, am I doing something wrong in the code that I showed in the first post that is causing my Adorner not move along with it’s associated Node?

If you believe I can achieve the same behaviour without Adornments then I would greatly appreciate any advice. As an alternative, I tried adding Popup controls to the Node’s DataTemplate definition and added logic to hide/show the popups depending on the node’s state but unfortunately the Popup control doesn’t get clipped by the viewport of the diagram.

Thanks
Justin

So do you want to use Adorners or Adornments? If you want to use GoXam Adornments, then maybe you should override one of the tools’ UpdateAdornments methods, say RelinkingTool.UpdateAdornments, to move your Adornment(s) as you see fit.
Don’t forget to call the base method. Register the replacement tool by setting the Diagram.RelinkingTool property, either in XAML or in code.

(Alternatively you could override Part.UpdateAdornments, but that’s harder to do than replacing a tool.)

Hi Walter

Thanks. I meant Adornments, not Adorners. Yes, before your reply I used Reflector to see what Part.UpdateAdornments was doing and I concluded that it was only updating builtin adornments or adornments that were registered as part of tool collection such as MouseDownTools. As my custom adornment is not part of a tool it would never get notified to update.

For now I will just add the go:Node.Location binding to the root element of the adornment’s DataTemplate to update it’s location relative to the node’s location as that seems to be the simplest solution.

Thanks
Justin