A common approach for communication between 2 ViewModels is this: http://stackoverflow.com/questions/2474768/mvvm-view-model-view-model-communications
The Mediator pattern or a Messenger class. But what about 6 ViewModels in one Window?
NewSchoolclassUserControl NewPupilUserControl
SchoolclassListUserControl PupilListUserControl
PupilsDetailUserControl AdministrationButtonBarUserControl (having buttons executing commands)
All this is in ONE Window. Do "you" really tell me now I have to setup a Messenger for those 6 Views and their Viewodels? That would be terrible...
6 UserControls in one Window, not even a big enterprise app has more UserControls in a window, so whats an accepted/best practice in that case?
I would be interested in someones opinion having experience with big mvvm applications :)
Some of those UserControl+ViewModels I would like to reuse at other places of my application. So put all in one UserControl is not that what I really want.
UPDATE: for the blind meise ;-)
private DateTime _selectedDate;
public DateTime SelectedDate
{
get { return _selectedDate; }
set
{
if (_selectedDate == value)
return;
_selectedDate = value;
this.RaisePropertyChanged("SelectedDate");
ObservableCollection<Period> periods = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
_periodListViewModel = new ObservableCollection<PeriodViewModel>();
foreach (Period period in periods)
{
PeriodViewModel periodViewModel = new PeriodViewModel(period);
foreach (DocumentListViewModel documentListViewModel in periodViewModel.DocumentViewModelList)
{
documentListViewModel.DeleteDocumentDelegate += new Action<List<Document>>(OnDeleteDocument);
documentListViewModel.AddDocumentDelegate += new Action(OnAddDocument);
documentListViewModel.OpenDocumentDelegate += new Action<Document>(OnOpenDocument);
}
_periodListViewModel.Add(periodViewModel);
}
}
}
@blindmeise
This ViewModel is datatemplated actually to a DataGrid. The Periods are the Rows. Each Row has a Column called Documents. I have a PeriodListViewModel 1 : N DocumentListViewModel.
The DocumentListViewModel is datatemplated with a UserControl containing a ListBox and below some buttons add/del/save/open etc...
A DocumentListViewModel has Commands and Action delegates executed in the "LessonController" so every action on a Document like add,del etc... can be done on the SelectedPeriodViewModel declared in the LessonController.
The above code just loads new data from database when the user changes the date in the datepicker.
Do you need more code or what do you say about my approach? I am eager to learn and I am glad about every critics!