Wednesday, June 27, 2007

WPF Docking Library - Persistence Support

From http://sourceforge.net/projects/wpfdockinglib/ you can download version 0.1.8 of WPF Docking Library. Major feature added is persistence support. I hope to have time to update article on codeproject, anyway persistence it's very easy to use.

To get layout state in xml format use DockManager.GetLayoutAsXml() and to restore a saved state you can use DockManager.RestoreLayoutFromXml().

The latter method need a handler to library client code because DockManager need to know how to associate dockable contents type strings with client instances during deserialization. This mechanism is almost identical to those you can found in DockPanel Suite.

Here a few lines of code:

if (!string.IsNullOrEmpty(Properties.Settings.Default.DockingLayoutState))
DockManager.RestoreLayoutFromXml(Properties.Settings.Default.DockingLayoutState,
new DockingLibrary.GetContentFromTypeString(this.GetContentFromTypeString));
else
{
//Show PropertyWindow docked to the top border
propertyWindow.DockManager = dockManager;
propertyWindow.Show(Dock.Left);
//Show ExplorerWindow docked to the right border as default
explorerWindow.DockManager = dockManager;
explorerWindow.Show();
//Show ListWindow in documents pane
listWindow.DockManager = dockManager;
listWindow.Show();
}



private DockingLibrary.DockableContent GetContentFromTypeString(string type)
{
if (type == typeof(PropertyWindow).ToString())
return propertyWindow;
else if (type == typeof(ExplorerWindow).ToString())
return explorerWindow;
else if (type == typeof(ListWindow).ToString())
return listWindow;
return null;
}


I suppose you can find same bugs in this version so if you need a more stable release you can wait for version 0.2.

7 comments:

Dr Love said...

Hi!
Nice update.
I just have a question. Do you have any plans on adding multiple dockmanager support? Its a pain for me to merge our codes each time a new version in released. Thanks, Anders

Anders said...

lol. sorry. Someone else was logged in on this computer ;)

adospace said...

Next release (0.2) has multiple dockmanager support, I promise!:)

Anders said...

Love you! :D
By the way. The persist methods does not persist the height and width of the windows.

Thats ok by me i have my own persist method anyway since i have lots of things in my windows that are saved into the project file. BUT, i cant fidn a way at runtime to set width heigh of a dockingconent? Hope you can shed some light. thansk!

/Anders

Anders said...

Hi Again. I just found a "bug". If i update the projectname and also update the Title property the Tab title is not updated.

Can i fix this somehow?

hax said...

Hi,

Thanks for the wonderful feature update. Indeed this is the best part of it.
Everything works fine as well excluding one thing.
I never had any issue with any XAML custom control (My form) but whenever I host controls in dockmanager in which I have interop component code using Visio 2007 OCX, i am getting following error.

While using your code I am getting following error:

LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Even if I do define my component in a documentpane, i am getting the same error. I didn't find anything wrong with my code.

Lapatin said...

I want the ability to group two floating windows together not only with main window.