ViewModel from WorkspaceData

Aug 4, 2010 at 4:54 PM


is that possible to get ViewModel instance from WorkspaceData object? Or is the idea of Workspaces to be isolated from each other and I should use ViewModels like you use ImageViewModel in your demo application.

The software I'm working on, is a MDI based CAD programm. That will have multi documents support and many tool windows to show and manipulate data from actual document (like VS IDE). By using WorkspaceData, View creates ViewModel and I have no idea how to get it.

Aug 5, 2010 at 10:56 AM

Yeah the idea behind workspacedata was simply to create a DataTemplate, then create a View using the workspacedata. Obviously the view is created in View first manner, which doesn't store the View/ViewModel instance against the workspacedata as essentially the  workspace data (for me at least) was simply to allow a new View to be created in View 1st manner. 


However you could just create a class that inherited from workspacedata and had extra property for ViewModel and then create a new NavProps DP, which when it creates the View based on the workspacedata, grabs the Views DataContext and passes it into your new workspacedata. You could even make the new ViewModel prop on the workspacedata a generic T and cast the Views DataCOntext to T in your new NavProps DP.


Hope this makes sense

Aug 5, 2010 at 12:08 PM

Thats good idea sacha,

my first solution was, creating a service that can store created viewmodels and import it in viewmodel constructor, where the VM can register him self in that service.

But after all I think AvalonDock and WorkspaceData, so View 1st, are not compatible. I started to implement CinchToAvalonDockBehivior to make AvalonDock more MVVM compatible and pass WorkspaceData as DockableContent to DockingManager. That works great at the beginning. The problem is, every time I switch betwin documents the NavProps.OnViewCreatorChanged fires and creates new ViewModel. And I don't know why.

So maybe DataTemplates is the only solution for me.

Aug 5, 2010 at 1:05 PM

Yeah I did have DataTemplates in mind, I am sure you will get to the bottom of it though

Aug 6, 2010 at 8:50 AM
Have you had a look at the following yet?
Aug 6, 2010 at 2:40 PM

Hi bcronje,

thank you for that link.

My project is ca. eight month old. It's my first WPF and MVVM project ever and I used MEF from first day, so I searched many about that all in internet. That means, I know soapbox project since first release and I used many ideas from that framework, so LayoutManager was part of my project too.

But now I understend little bit more about what I'm doing and why. With CinchV2 I started big refactoring, or I can say, restart of that project and I will do it more clear and pattern conform, use more Cinch features and and and. That means, I don't like that LayoutManager anymore. It's not MVVM conform. I have FrameWork references in my ViewModels and it's very coupled.

I have the better solution now and I'm very happy about that. It's absolute independet from my project or other libraries. It's a "simple" Behavior that managed ViewModels for AvalonDock. So every one can use it to make AvalonDock more MVVM freandly. In xaml it looks like that

<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}"/>

thats all. No matter what type your ViewModel have, it works

So every one, who want's it, I can publish that behavior. You too sacha, maybe you will use AvalonDock for some projects.

I started discussion at avalondock to integrate this in avalondock librery, so I hope it will be heppen.

Aug 8, 2010 at 7:39 AM
See told you, you would sort it out.
Aug 8, 2010 at 7:54 AM

Hi sacha,

after I tested a lot with my behavior, I found out, that actual AvalonDock is bugy and slow, especialy on my x64 server machine. So question on you, what are you using for MDI evironment?

Aug 8, 2010 at 4:20 PM

At work we use SandDock, which costs about $199 per license, but its ace.