After finishing some by-hand projects, my recent project implements the MVVM pattern using Caliburn.Micro - but I still struggle with some architectural problems. Mainly:
My ViewModel contains a BindableCollection
ProfilesCollection
of Profiles
. My view has a button to add new profiles. But since the profiles are complex I want the button click to open a new window where I can fill in the details, and then return back to the main window.
In my previous by hand approach I made the ProfilesCollection
static so that it was accessible throughout the whole application, and as click event I just opened a new window, where I then stored the new profile in the static Collection
.
What would be the right MVVM approach? Create a new view/ viewmodel instead of a new window? How do I manage them, and how do I pass the Profile
I create back to the MainViewModel?
Thanks!
you can simply open a new dialog/window to fill your details. check out my apporach here
I would start by passing the
ProfilesCollection
into aProfilesViewModel
along with aProfilesView
for selecting the profile you want to edit and for adding/removing profiles.Second, I would have a separate
ProfileViewModel
andProfileView
. TheProfileViewModel
would have aShowDialog
method that would callShowDialog
on theProfileView
child window. This will allow theProfilesViewModel
to set the profile on theProfileViewModel
and then callShowDialog
, which will fit the MVVM pattern nicely.For more information on this, check out the Wpf Application Framework.