Possible Duplicate:
The best approach to create new window in WPF using MVVM
Hello Friends,
I have two view MainWindowView and AddCustomerView. I have menu containing buttons in MainwindowView.xmal.
How could i popup AddCustomerView from MainWindowViewModel by clicking on button.
My App.xmal.cs for Startup code is..
base.OnStartup(e);
MainWindow window = new MainWindow();
var viewModel = new MainWindowViewModel();
window.DataContext = viewModel;
window.Show();
What is the code for showing AddCustomerView in buttonexecute code.
public void AddNewCustomerWindowExecute() //This is button handler
{
// How to show AddCustomerView from MainWindowViewModel
}
Check out this "deep dive MVVM video". Laurent Bugnion shows the Concept of the IDialogService and explains the concepts very well... plus the source code should also be available... The concepts apply also to wpf
http://channel9.msdn.com/Events/MIX/MIX11/OPN03
HTH
Handle it in the view
Probably the most simple approach.
ViewModel exposes an event
This has one drawback: it requires lots of manual coding.
Handle it in the view
Controller that handles all your views
Mediator pattern
Some MVVM frameworks (e.g. MVVM Light) use this pattern.