This project is read-only.

Store Data with each DockableContent

Mar 21, 2011 at 3:37 PM

Is there an easy way to store additional data with each DockableContent in the layout file?

The reason why I ask is:
I'm creating all DockableContent on the fly by user interaction. At design time I don't know how much DockableContent of each type the user will create and I don't wan't to limit the number.
For each DockableContent the user will apply different settings, that should be stored alongside with this content in the layout file.

I don't like the idea of changing the source code of AvalonDock, but at the moment I think this is the only practical way to achieve this.

Mar 21, 2011 at 5:29 PM
Edited Mar 21, 2011 at 5:42 PM

Hello,

you can declare this handler:

dockingManager.DeserializationCallback = (s, e_args) =>

{ ...

It will be called by the docking manager when reloading a layout.

e_args.Content should be the DockableContent (never tested with DocumentContent) and e_args.Content.Name the name that is used to identify the DockableContent in the layout xml file.

It is possible to define this name before saving the layout. We used it to store a key (in fact a composite key) and restore values using this key.

Hope this helps

Bernard from Sofa, an AvalonDock wrapper.

Mar 23, 2011 at 8:30 AM

Hello Bernard,

this is a good idea and my content items already have a key, but...

How can I store my extra data into the layout file?

I thought about making the DockingManager part a ChildNode of my surrounding Xml structure, but DockingManager always loads the document as a whole with Restore(XmlDocument doc). And then it checks for root element "DockingManager".
It also checks for exactly 3 ChildNodes, so I don't see a possibility to add my data as an extra ChildNode.
The only possibility I see at the moment is to store all extra data in Content.Name, which would give me very long names, and is not very nice.

Do you know a way to make the DockingManager data a part of my own xml file?

Mar 23, 2011 at 8:09 PM

"How can I store my extra data into the layout file?" Separation of concerns or "Render unto Caesar…: I think the best is to store AvalonDock data in AvalonDock file and your data in your file. Using System.Xml.Linq you can achieve this very easily. See in our Contact examples if you need one.

In the same way storing the layout in your own file is a complicated work and I don't think the result worth it. 

Bernard from Sofa, an AvalonDock wrapper.

Mar 24, 2011 at 12:13 PM
bernardsofateam wrote:

Using System.Xml.Linq you can achieve this very easily.

Thank you for the pointer, I never worked with xml.linq but I will sure look into this.

 

bernardsofateam wrote:

In the same way storing the layout in your own file is a complicated work and I don't think the result worth it. 

 I think about this, because of the hassle with two seperate files having to be in synch.
What makes you think this is complicated?
In fact I think this should be a very easy task. AvalonDock could search the XML tree for it's root element "DockingManager" instead of relying on the DocumentElement.Name is "DockingManager".

I will go now for the linq option with seperate files, but maybe in my final version I will modify AvalonDock to store it's data into my own XML.

May 4, 2011 at 1:00 PM

Update:

No need for two seperate files and no need for Linq either.

I ended up by saving the layout after my own serialized objects into my own file via SaveLayout(Stream).

When loading, my extra data is already loaded before DockManager calls my DeserializationCallback, so I can give each DockableContent its settings in my callback.