datacontext - avalondock mvvm -


using avalondock seems challenging in mvvm environment. detach documentpane shellview, loose corresponding datacontext , view empty. when reattaching, gets normal.

does have solution ?

here's use currently; app hase couple of dockable panes, each having own viewmodel. these viewmodels exposed properties main window's viewmodel, datacontext of main window. trick refer datacontext using static application.current instance's mainwindow.datacontext.

for example:

class mainwindowviewmodel {   public windowaviewmodel {get; set;}   public windowbviewmodel {get; set;} }    //this goes in app.xaml.cs, because mainwindowviewmodel has constructor   //with arguments, else set window.datacontext in xaml var window = new mainwindow(); window.datacontext = new mainwindowviewmodel( ... ); 

mainwindow's xaml:

<ad:dockingmanager>   <ad:resizingpanel orientation="horizontal" >     <ad:dockablepane>       <ad:dockablecontent>         <l:windowa datacontext="{binding path=mainwindow.datacontext.windowaviewmodel,                                  source={x:static app:app.current}}"/>       </ad:dockablecontent>       <ad:dockablecontent>         <l:windowb datacontext="{binding path=mainwindow.datacontext.windowbviewmodel,                                  source={x:static app:app.current}}"/>       </ad:dockablecontent>     </ad:dockablepane>   </ad:resizingpanel> </ad:dockingmanager> 

not sure how works out large modular applications though, i've seen a sample application in prism being used sofa (an avalondock wrapper) might want check out how did it.


Comments