Diagram layout after Load


This is for GoXam for Silverlight, V1.3.3.5

I’m creating an MDI type application where each document pane is a GoXam diagram. The model for each diagram is a GraphLinksModel. Initially I can create a new document and I add some nodes to it. Please see the following screenshot:

I then save the diagram using the following line:

Model.Save<TNodeType, TLinkType>(RootElementName, NodeElementName, LinkElementName).ToString();

Where Model is the model contained by the diagram.

This generates the following XML:

I then close the pane, open it and load the diagram using the following code:

XElement root = XElement.Parse(xmlDiagramData);
Model.Load<TNodeType, TLinkType>(root, NodeElementName, LinkElementName);

This produces the following screenshot:

Initially, the nodes are displayed at the correct location but then that are aligned top left as can be seen in the screenshot.

My question is: how can I configure the diagram to respect the original coordinates of the nodes instead of having them automatically aligned as in the second screenshot?

The Style for the Diagram is currently configured as follows:

Please let me know if you need more information.


I think you want to set the Diagram.InitialPosition.
You could always set it to be the origin, or you could save it in your XML.
But note that Diagram properties are not part of the model, so you will need to add any such properties yourself to the XML that you save and load.

Hi Walter

According to the documentation, InitialPosition is set to new Point(Double.Nan, Double.Nan) by default which suggests it won’t effect the initial value of the diagram’s panel position. This sounds like what I want.

So I played with InitialPanelSpot instead. By setting it to None I managed to achieve what I wanted.
However, now I have another problem. If you look at the screenshots in the first post, you can see that diagrams are contained in docking panes. If I undock a pane containing a diagram and then re-dock it, the diagram parts get shifted/aligned top left again. It’s as if the diagram bounds shrunk when the pane was undocked, to the minimum required size. Is there anyway to prevent this automatic shrinking from happening?

Also, I don’t quite understand the difference between InitialPanelSpot and InitialDiagramBoundsSpot. Do you mind explaining it to me?


If there’s no “real” value for Diagram.InitialPosition, other factors/properties may affect the initial position when a model is loaded.

Did setting InitialPosition=“0 0” not work for you?

Is your diagram inside a regular WPF TabControl? Or is it inside some other kind of tab control? If the latter is the case, when the controls in a tab (including a diagram) are unloaded, all of the Nodes and Links are removed in order to avoid memory leaks. It does not do that by default if it is inside a TabControl, because it then assumes that the user is just switching tabs. But it cannot know about other kinds of tab controls. You can avoid that “safe” behavior by setting Diagram.UnloadingClearsPartManager=“False”.

Thanks for the quick response.

Yes, setting InitialPosition=“0 0” does work. Not sure why I didn’t try that first.

The diagram is contained in a RadPaneGroup (http://www.telerik.com) which is a type of RadTabControl. Unfortunately, setting Diagram.UnloadingClearsPartManager=“False” had no effect.


That unloading business applies when switching tabs.
I thought that might explain the behavior you mentioned when you started talking about docking.

The “unloading” property should have no effect when the diagram/tab is created/loaded for the first time, which I thought was the situation you first described.

No, sorry for the confusion. Switching tabs works fine. It’s when I undock the pane into a floating window that the diagram bounds seem to “shrink” and align top left.

Well, I’m not sure, but I am guessing that the undocking or docking operation is causing the Diagram control to be resized. Perhaps that is causing the Diagram.Panel.Position to be shifted to a more natural position.

I suppose you could override DiagramPanel.ComputeDiagramBounds to be a no-op.
In order to use your subclass of DiagramPanel you should replace the Diagram.Template to be a copy of the standard ControlTemplate (see the GenericWPF.xaml file in the docs directory), substituting your class instead of the standard go:DiagramPanel element.