AvalonDock + MVVM friendly

Aug 5, 2010 at 5:35 PM
Edited Aug 5, 2010 at 5:44 PM

Hi adospace,

I'm working on a project with MVVM pattern and use your great library. To get DockingManager more MVVM compatible I'm coding a Behavior for it, where you can binding DocumentSource and ToolWindowSource to ViewModels, so docking content will be generated thru this behavior class automaticly.

When you or someone intresting in that, I can post the code or send it as soon as it's ready.

The other thing, it's not possible to set the size for DockingContent from code behind. As I looked at your code, how I can make it, I found the solution, but it needs some changes and bug fixes at DockingManager class.

1. wenn you create new DockablePane, you can set ResizingPanel.SetEffectiveSize from content that should be added to that pane. like this

DockablePane pane = new DockablePane();
ResizingPanel.SetEffectiveSize(pane, ResizingPanel.GetEffectiveSize(content)); 

2. At this place, the new pane will get allways Width or Height of 200 and red marked are bugs

DockablePane dockParent = content.ContainerPane as DockablePane; 
if (content.ActualWidth == 0.0 && 
    ( dockParent.Anchor == AnchorStyle.Left || dockParent.Anchor == AnchorStyle.Right)) 
    ResizingPanel.SetResizeWidth(dockParent, new GridLength(200)); 
    ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0)); 
else if (content.ActualWidth == 0.0 && 
    ( dockParent.Anchor == AnchorStyle.Top || dockParent.Anchor == AnchorStyle.Bottom)) 
    ResizingPanel.SetResizeHeight(dockParent, new GridLength(200)); 
    ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0)); 

Here you can set the GridLength from EffectiveSize property, when it's set.


Thank you, Dima

Aug 6, 2010 at 6:48 AM

Hi Dima,

I'm interested in the MVVM behavior you're developing. Please let me know when it's ready.


Aug 6, 2010 at 4:22 PM
Edited Aug 6, 2010 at 4:22 PM
We are using AvalonDock in combination with Catel (see http://catel.codeplex.com/). We created a wrapper that automatically saves or closes the data on the view model. This way, we simply have to create a DocumentContent with a ViewModel and that's it. Maybe we will post an example of the wrapper soon.
Aug 6, 2010 at 4:56 PM

I don't know any thing about Catel, looks like a great framework. But with my behavior, you don't have any issues to know anything about avalondock in your ViewModel. ViewModel represets data and thats all, behavior doing the rest.

You just need to know that behavior sets the current item with ICollectionView, so you can use it from view model too. The rest is very simple, just this piece of code

<ad:DockingManager x:Name="_avalonDockManager">
          DocumentsSource="{Binding DocumentMenager.Documents}"
          ToolWindowsSource="{Binding ToolWindowManager.ToolWindows}"
          DockingStyle="{Binding ToolWindowManager.DockingStyleForCurrent}"
          DockingPosition="{Binding ToolWindowManager.DockingPositionForCurrent}"
          DocumentClosingCommand="{Binding DocumentMenager.DocumentClosingCommand}"
          ToolWindowClosingCommand="{Binding ToolWindowManager.ToolWndowClosingCommand}"/>

I hope it will be integrated in AvalonDock library

Aug 8, 2010 at 8:58 PM


can you please describe how you created the Behavior?


Aug 9, 2010 at 1:07 AM

Hi all,

The Behavior is near to ready and at the moment I will not continue work on it. The performance and bugs on AvalonDock impel me to look for alternative.

But I created a small demo project (but no comments, have much work), so every one can use it and improve it.

link : http://www.sendspace.com/file/z664mm

Good luck with it all,


Nov 23, 2010 at 1:51 PM

Thank you very much indeed, Dima for sharing your sourcecode.

More or less I'm quite disappointed about the kind, of how the original developer keep shtum about this important MVVM-matter.


Dec 30, 2010 at 6:21 PM


Thank you very much for posting your code....you have saved me a ton of time.  Its a poor show that AvalonDock have not addressed this issue already.

Kind regards,


Feb 18, 2011 at 2:54 PM

I am struggling to get MVVM working with Dimas approach, which basically works. But I also use RestoreLayout and it seems that items that are created by RestoreLayout are not added to the DocumentSource collection. So I end up with e.g. 5 items in DockingManager.Documents (4 from RestoreLayout +1 from manually adding one) and only 1 item in DocumentSource (the one I added explicitly through the Behaviour).

This seems to be a bug, but as I understand it the two collections should always be in sync!?

Feb 21, 2012 at 10:48 PM


I was wondering if you'd seen these two articles,


I've also noticed that version 2 of AvalonDock is going to be MVVM compatible.

Did you get a copy of Dimas's code as the link above no longer works.


Feb 22, 2012 at 6:20 AM

Hi John,

yes, I saw the codeproject articles but only through the anouncement of version 2 of AvalonDock 2, there was a link there. (wish I had known them before). Anyway, I am using a commercial tool at the moment (DevExpress), but I closly watch the development of V2 here.

Thanks for your comment.