On using DockSiteLayoutSerializer to restore ToolWindows

Docking/MDI for WPF Forum

Posted 9 years ago by Adam Petaccia
Version: 10.2.0531
Avatar
I'm having some problems using the DockSiteLayoutSerializer class, and I'm not sure if because what I'm trying to do is supported or not.

What I would like to do is be able to save the positions and sizes of ToolWindows across application restarts. I don't want the ToolWindows to automatically restore, but should they be opened they should then be restored to their previous state (including docking position/location, size, and autohide settings).

I've tried setting LazyLoad, but there doesn't seem to be any effect as all the toolwindows just spawn on the right now.

What is required for the DockSiteLayoutSerializer to "remember" which windows are which? Is this possible?

Comments (4)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

The lazy-load feature uses the "name" (as specified by x:Name in XAML) as the unique identifier. So you'd need to make sure that the ToolWindows have a unique name before saving the layout, and then while loading the layout or opening the ToolWindow. Our Sample Browser shows an example of how the lazy-loading feature works.

Also, keep in mind that the lazy-loading allows you to restore the layout of ToolWindows that have not been created/registered yet. So if your ToolWindows are already created/registered, but just not opened/visible, then loading the layout will open them.


Actipro Software Support

Posted 9 years ago by Adam Petaccia
Avatar
> Also, keep in mind that the lazy-loading allows you to restore the layout of ToolWindows that have not been created/registered yet. So if your ToolWindows are already created/registered, but just not opened/visible, then loading the layout will open them.

So to get the desired effect (Window's aren't automatically spawned, but will come in with previous settings restored)

* Application starts up
* Create docksite
* Retrieve stored DockSiteLayout and apply to docksite created above
* Enter main loop
* When user does something which would spawn a toolwindow (they start off closed) it is created, added to docksite
* At this point, if I understand correctly, you're saying as long as the name is unique and the same as before, the ToolWindow will have the same properties (dimensions, location, rafting, docking direction, etc) as before?
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

That is correct. If you are seeing something different, then please try it out with our Lazy Loading sample and compare that with your code. If that doesn't help, then please put together a small sample project that reproduces the issue and email it over to our support address.


Actipro Software Support

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

Thanks for the sample. The issue here is the order of operations. Your code effectively looks like:
Tool Window tw = new ToolWindow(this.dockSite) {
    Name = "MyToolWindow",
};
The problem is this registers the ToolWindow before it's Name is set. So when it looks for the lazy-load layout data, the Name is empty and nothing is found. The code above effectively translates to:
Tool Window tw = new ToolWindow();
this.dockSite.ToolWindows.Add(tw);
tw.Name = "MyToolWindow";
The Name needs to be set before the ToolWindow is registered. So this code works:
Tool Window tw = new ToolWindow() {
    Name = "MyToolWindow",
};
this.dockSite.ToolWindows.Add(tw);
As would the other ToolWindow constructor overload that takes both a DockSite to register with and a Name.

Hope this helps.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.