Serializing custom DocumentWindows

Docking/MDI for WPF Forum

Posted 14 years ago by Bradley
Avatar
Hopefully there's a document somewhere that I'm just missing. I've got 2 custom DocumentWindows, WorkSpaceWindow and ChartWindow. I have a class called DocumentsView which can host multiple WorkSpaceWindow's via this code
<docking:DockSite x:Name="WorkspaceDockSite" CanDocumentWindowsEditTitles="True" >
                <docking:Workspace>
                    <docking:TabbedMdiHost TabPlacement="Bottom">
                        <docking:TabbedMdiContainer>
                        </docking:TabbedMdiContainer>
                    </docking:TabbedMdiHost>
                </docking:Workspace>
            </docking:DockSite>
And each WorkSpaceWindow can host multiple ChartWindow's via
<docking:DockSite x:Name="InnerDockSite" WindowActivated="InnerDockSite_WindowActivated">
        <docking:Workspace>
            <docking:TabbedMdiHost x:Name="tabbedMdiHost" TabPlacement="Top">
                <docking:TabbedMdiContainer>
                </docking:TabbedMdiContainer>
            </docking:TabbedMdiHost>
        </docking:Workspace>
    </docking:DockSite>
All this works fine, but now I want to serialize my layout. Right now I don't care about serializing the data that's in ChartWindow or WorkSpaceWindow, just want to be able to serialize all the WorkSpaceWindow's that are in my DocumentsView, and then any ChartWindow's that are in each of the WorkSpaceWindows. I've added [Serializable()] to the top of both classes, and the code to save the layout is

            if (layoutSerialize == null)
                layoutSerialize = new DockSiteLayoutSerializer();
            //Just WorkSpaceWindow till that type works
            layoutSerialize.CustomTypes.Add(typeof(WorkSpaceWindow));
            layoutSerialize.SaveToFile(@"C:\layout.mqtd", WorkspaceDockSite);
but when I run this and close the app I get this error on the SaveToFile line
"{"Cannot serialize member System.Windows.Input.InputBinding.Command of type System.Windows.Input.ICommand because it is an interface."}" so I'm pretty sure I'm not doing something right. Thanks!

[Modified at 05/03/2010 08:19 PM]

Comments (8)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bradley,

We still have a TODO item to make it easier for custom types to be serialized/deserialized. I'll mark your post down with that TODO item. so you will be notified when it's completed.

However in the meantime, what I'd recommend is that you scan the layout XML before you load it. Look at all the ToolWindow tags and if there are some listed for your custom tool window type that haven't been registered yet with the DockSite, create them. Then load the layout and they will be found.

This won't serialize/deserialize any custom properties you have your type though. In addition, you can't mark the class as serializable, as the base WPF classes are not designed to be serialized.

In the future we hope to add some sort of callback event, etc. that will let you handle this easier but that should get you going for now.


Actipro Software Support

Posted 14 years ago by Bradley
Avatar
I will give this a try, but I don't think this will help as we're not using tool windows (notice the subject says DocumentWindows) and if I recall, the XML doesn't spit out UIElements for these custom DocumentWindows at all if I don't include this line


layoutSerialize.CustomTypes.Add(typeof(WorkSpaceWindow));

and when it is included I get the error about not being able to serialize that window that I posted in the first message.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bradley,

Even if the type isn't serialized, the serialization code will be constructed for the specified type. We are leveraging the XmlSerializer built into .NET. The type you are passing is not serializable, since none of it's base classes are serializable. So when XmlSerializer tries to build the code to serialize/deserialize your object, it fails.

For the Docking & MDI classes, we actually serialize a helper object instead (i.e. XmlToolWindow for ToolWindow). We map serialized properties to/from each object when saving/loading.

Keep in mind also, that we don't currently save/load layout information for DocumentWindows. That is a higher priority TODO item, that we hope to get to after we get our new Silverlight controls out.


Actipro Software Support

Posted 14 years ago by Bradley
Avatar
Any update on when this feature will be implemented, now that the Silverlight controls are out?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We are planning on adding it for the WPF Studio 2010.2 release that we are working on now.


Actipro Software Support

Posted 14 years ago by sean duggan - bank of america
Avatar
Hi,

I have a similar problem. when I serialize the docksite and restore it, the DocumentWindows and any SplitContainers are not restored even thought they serialzed okay without the contents.

Will this be fixed in the next release as well? and when do you think it might be available - an eta?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Sean,

We've added support for serializing and deserializing DocumentWindows in the upcoming release of WPF Studio 2010.2. We plan on releasing it early next week.


Actipro Software Support

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bradley,

Just fyi, we've added enhanced support for custom DocumentWindow and ToolWindow types. This new auto-creation feature will allow you to create/initialize a custom DocumentWindow or ToolWindow instance, or allow our code to automatically create them for you.

You can see this in action in the current version of WPF Studio.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.