views:

353

answers:

1

I'm very new to MVVM and even WPF to some degree so bear with me...

I've got a MVVM application that has a main window, containing a viewmodel instance of different types depending on application state. One of these viewmodels is an options screen which contains a button to restart the application and log into the database as a different user. Using RelayCommand, how can I have the parent, (the main window) handle this command and issue a Window.Close() method call?

+1  A: 

Define the RelayCommand on the parent view model. The Associated handlers will also be defined in the parent view model.

Now, when you creat the child view module pass the Paremtn View model object in to the Child ViewModel in the constructor (Dependency Injection Pattern).

Now you can set up the command binding for your view or view model.

Te other alternative would be to actually use a routed command instead of the relay command and let it bubble up to you parentview model.

thrag
this actually makes perfect sense and I feel like a fool for not realizing it before.
Firoso