Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF + MVVM with multi-windows handling

Tags:

mvvm

wpf

I was looking at a video that explain pretty well MVVM. However, it seem to only show an one window application model. What do you have to do if you want to handle a multi-windows model ?

From what i see.. the app.xaml is linked to the MainWindow (as DataContext). Since app.xaml is the starting point it execute the MainWindow. The MainWindow have ViewModels as a bind so it can handle his ViewModels.. but all this are only for one windows.. what happen with you want to introduce a second window ? How do you proceed ?

Thanks.

like image 599
Rushino Avatar asked Feb 15 '26 23:02

Rushino


1 Answers

You can instantiate your view (Window) type from the main windows view model via a service, injected as an abstraction. You can then set the DataContext of this Window programmatically within the service, locate the appropriate view and use myWindow.Show() or myWindow.ShowDialog() to display the Window. An MVVM framework such as Caliburn.Micro has a WindowManager for taking care of the view location and view/view model binding for you.

like image 59
devdigital Avatar answered Feb 21 '26 14:02

devdigital