I'm using GoXam for WPF v1.0.7.3, and use DiagramData.Save<...>(..) to persist to a XML file and invoke DiagramData.Load<...>(..) to load persisted XML back to diagram visual. It looks like after the XML loads, even though there is Location persisted with Node data, the diagram always draw the node in the Location of (0,0).
One simpliest example is that I just saved a one-node diagram,
here is the persisted XML content:
Here is my data bound data template for Data.Location in XAML:
Perhaps the Location is correct. If you save it, what Location does it have?
If the Location hasn’t changed, it’s probably because the Diagram positioned the contents to be at the top-left corner of the panel. Specify values for the Diagram.HorizontalContentAlignment and VerticalContentAlignment attributes.
I tried saving and loading a diagram of a single node using the State Chart sample in GoWpfDemo. It worked as you would expect. So I wonder what might be different in your application.
Oh, perhaps you have a Diagram.Layout that is always performing a layout after loading the nodes from XML. In version 1.1 by default you’ll get the behavior that you want. In version 1.0 the easiest solution is not to declare a value in XAML for the Diagram.Layout, but to create it and perform the layout in code only.
My app requires to drag note from palette to the diagram surface to build the diagram, the node needs to stay whereever user drops it, so I made sure there is no Diagram.Layout is set.
I also noticed when the one node XML loads into a Dragram, the note appears at the correct location, then suddenly moves to the left-top corner, behaves like a left-top aligned layout is applied by default.
Do you think there is a work around? Like to programmactically set the Diagram's origin coordinates after reload? Or anything else I can try to tell the Diagram works in "absolute-positioned" mode?
Hmmm. It should be OK to set Diagram.InitialStretch if that’s what you want, but it shouldn’t be required to get the (default) behavior that you are seeking. The State Chart sample, for example, doesn’t set InitialStretch.