I have this DocListViewModel bound to a DocListView with a DataGrid that list documents. When I double click a row, I want to open a window showing that document but only one window per document.
So it all starts like this:
var wm = new WindowManager();
var vm = new DocEditViewModel(Parent, docID);
et voila, my document shows on a Window using DocEdit.WindowView.xaml (DocEditView.xaml was temporarily needed for other purpose).
The DocEditViewModel implememts IViewAware and keeps a static Dictionary<int,object> where I keep the document's ID and the attached view like this
public void AttachView(object view, object context)
On the other hand, when CM asks for a view, if I have one, I give it to CM like this:
public object GetView(object context)
object view = null;
if (_views.TryGetValue(Model.DocID, out view)) // this "if" is useless as a view is returned no matter what
I must add I can't inherit from Screen as I am already inheriting from Csla.Xaml.ViewModel<Doc> (this is why I have Model.DocID instead of plain DocID). So I just implement IViewAware, IChild and IHaveDisplayName.
I didn't get to the part where I must clean the cached view but I'm planning to.