Layout Serialization

Docking/MDI for WPF Forum

Posted 16 years ago by Andrey
Version: 4.5.0485
Avatar
Hello everybody,

I'm trying to serialize the docking layout with some custom data describing my controls hosted by the ActiPro docking site using the Help:

Layout Serialization:

...
One benefit of our XML object hierarchy serialization framework is that you can insert and later retrieve information anywhere within the serialized data. Any time an object is serialized or deserialized, an event fires. You can intercept this event and save/load custom data.
The Serialization topic explains how to do this.


Serialization:

...
The Node property in the event arguments provides the XmlObjectBase that is being serialized, and that represents the serializable data for the object indicated in the Item property. You can set the Tag property of the Node to save any custom data with the serialized data.
For a good example of serializing custom data, see the NavigationBar Layout Save/Load QuickStart.


The Quickstart has the following:

private void OnObjectSerialized(object sender, ItemSerializationEventArgs e) 
{
// Store some custom data in the layout... this is called every time an object is serialized
    if (e.Node is XmlNavigationBarLayout)
        e.Node.Tag = "Custom data in root layout element, injected in this sample's code-behind";
    else if (e.Item == mailPane)
        e.Node.Tag = "Custom data for Mail pane only";
}
It appears that "custom data" can only be string, is that correct?

Thanks,
Andrey.

Comments (7)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andrey,

No, actually you can place any serializable object in there, not just strings. Our sample just shows strings though.


Actipro Software Support

Posted 16 years ago by Andrey
Avatar
Hi,

Thanks for the quick answer! Here is what I'm doing:

My test serializable object:

[Serializable]
public class SerializableSample
{
    public String Data;
}
My ObjectSerializedHandler handler:

protected virtual void OnPluginSave(Object sender, ItemSerializationEventArgs args)
{
    ToolWindow window = args.Item as ToolWindow;
    if (window != null)
    {
        SerializableSample sample = new SerializableSample();
        sample.Data = "Some custom data";
        args.Node.Tag = sample;
    }
}
Exception text:
"The type SerializableSample was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."

What am I missing?

Thanks,
Andrey.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andrey,

Can you send over a simple sample project that shows this error and we'll take a look? The XmlInclude attribute can be used generally however in this case you would need to have it set on the Tag property which can't happen since we define it.

The other thing you can do is statically define your class by overriding the GetXmlSerializer method on the layout serializer class. When creating the XmlSerializer that is returned by the method, we specify the types that can be serialized. So there you'd need to add yours.

One idea we had is to add a new property to the serializer that is a list of custom Types that be serialized and we'll add those to the XmlSerializer.

But if you could send over a simple repro project, we'll test the idea with that. Email it to our support address and please reference this post. Thanks!


Actipro Software Support

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Disregard the sample request. We modified our NavBar Layout sample to repro and test the new CustomTypes property on the serializer and it works. The update will be in the next maintenance release.


Actipro Software Support

Posted 16 years ago by Andrey
Avatar
Hi,

As far as I understand you were able to reproduce the issue and it is to be fixed. Please correct me if I'm wrong.

GetXmlSerializer is not an option because static definition means, again if I understand it right, customizing the XmlAttributeOverrides collection before it is passed to the XmlSerializer ctor.

Thanks for you help!
Andrey.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The GetXmlSerializer method in the core serializer is implemented to create an XmlSerializer that is passed the types that will be included in the serialization. We supply some default ones (basically our Xml* classes in the same namespace).

So what we've done for the next build is added a CustomTypes collection. You can add your custom Types that will be serialized there and it will add them to the XmlSerializer from within our updated GetXmlSerializer method implementation for you.

The NavigationBar Layout QuickStart has been updated for the next build to show this too.


Actipro Software Support

Posted 16 years ago by Andrey
Avatar
Thanks!
The latest build of this product (v24.1.3) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.