Is there an example MVVM + AvalonDock application ?

Oct 9, 2009 at 8:59 PM

Is there an example MVVM + AvalonDock application ?

Oct 13, 2009 at 4:33 AM

I am in the process of writing one and should be releasing it shortly as open source.  Do you have any particular questions?

Oct 13, 2009 at 12:35 PM

Hi swhitlock,

I'd be interested in that example you're writing, specifically in relation to the Prism framework if thats where you're going with it. Im pretty new to MVVM, WPF and Prism so any starters would be much appreciated.

Until now the best thing I've found regarding this is the following on SO, although this might have more to do with Prism and AvalonDock than MVVM.

http://stackoverflow.com/questions/924074/prism2-region-adapter-for-avalondocks-documentpane-and-dockingpane

Cheers,

Dave

 

Oct 13, 2009 at 3:02 PM

I'm actually using MEF instead of Prism, though I'm sure most of the ideas would still apply.  I'll post back here when I have something to release.  It's pretty close.

Oct 14, 2009 at 3:51 PM

@swhitlock

I'm looking forward to this!

Oct 14, 2009 at 4:48 PM
Edited Oct 14, 2009 at 4:51 PM

Hi swhitlock,

      I am just trying to get handle on avalondock with MVVM to evaluate if this feasible for professional grade application.
The documentation is almost no help, (the api doc just has method names but no documentation on what they actually do) whatever we have is only example scenarios and not practical situation. Like how easy would it be to manage children from the MainWindowViewModel which is ViewModel for avalonDock and how to delegate all events from avalondock view component to my ViewModel. Once it is in ViewModel it would be very easy I think.

So, not any particular issue/questions yet. But general reference application that can give me confidance that this will work with MVVM and will be not too much away from general design practices.

 

Oct 14, 2009 at 6:19 PM

First of all, AvalonDock is *not* MVVM.  So what I had to do was abstract it as a "LayoutManager" service.  The main window view model provides a LayoutManager to bind to which somehow or other ends up returning a DockingManager object that ends up being the main content on the main window.  From there, you add and remove documents and "pads" (which are ViewModels) to the LayoutManager service which takes care of wrapping them in the appropriate DocumentContent or DockableContent controls, and puts them into the Docking Manager.

In order to apply the View to each document or pad viewmodel, I use DataTemplates.  So if you had a toolbox called, PropertiesViewModel, you make it implement the IPad interface, and hand it to the LayoutManager service for display.  The LayoutManager "remembers" where it was last time, and displays it there again, or puts it in a default place.  You also define a PropertiesView data template for the PropertiesViewModel type and make sure that's either in your application resources or your window resources as appropriate.  That's where I used a trick from MEF to do it: http://stackoverflow.com/questions/842571/using-mef-to-import-a-wpf-datatemplate

WPF then automatically applies the data template to the PropertiesViewModel when it sees it inside the DockableContent control.

Simple, eh?  :)

- Scott

Nov 2, 2009 at 4:11 AM
Edited Nov 2, 2009 at 4:12 AM

Ok, sorry for the delay.  I'll probably have the source posted sometime next weekend.  In the mean time you can download the demo application that uses it here:

http://soapboxcore.com/images/downloads/soapbox.demo.setup.msi

This is AvalonDock as part of a fully MVVM application.  If you want to see what it's really "demo'ing", the SoapBox.Demo.PinBall.dll is an extension to the core framework (it adds itself to the View menu, adds itself to the Options dialog, and adds the Score and Level indicators to the Status Bar, not to mention adding the pin ball table itself, the Instructions Pad, and the About Box), and the SoapBox.Demo.HighScores.dll is an extension to the extension.  You can remove these DLLs from the directory, restart the application, and you just lose that one feature.

Feedback appreciated.

Nov 3, 2009 at 5:32 PM
Edited Nov 3, 2009 at 5:32 PM

can you make it zip of your .dll/solution ? I hate installing stuff with msi installer .

1.) also, Is your solution open source ? 
2.) does it allow me the use(reference) my avalonDock dll ?

Nov 4, 2009 at 11:18 AM

@sendi_t34, I'll be putting the source up on an SVN site this weekend.  You can rip out the AvalonDock one I have in there and put your own in.

Nov 5, 2009 at 5:03 AM

Ok, I just pushed the first version up to the public repository:

I've started working on some documentation here:

The "SoapBox Core" framework is just my attempt to create a base for an application I'm writing.  The requirements were: WPF with MVVM and Extensible with 3rd party add-ins, similar to SharpDevelop.  If you guys can use it or you have any feedback, that would be excellent.  The application I'm writing will be GPL, but we decided to release this as LGPL so others can use it in proprietary applications.  I think there are a lot of people out there trying to figure out how to make MVVM actually work, and few examples, so I hope this at least gets people thinking.

It comes with a (pin ball) demo so you can get an idea of how you can write an application that provides documents and pads (dockable content) and control when and how they get shown.

Note: this doesn't have the very latest patches from AvalonDock in the Layout module.  I will be pulling those in and publishing a new version eventually.

- Scott

Nov 8, 2009 at 4:18 PM
Edited Nov 8, 2009 at 4:19 PM

I wrote up an article which gives an introduction to how to use it and posted it on CodeProject: