3
votes

I have a window control that contains four user controls (screens) in a wizard style environment. (i.e. only one user control will be viewable at all times) The window control has a series of buttons that act as the primary navigation between all the user controls.

----------------------------------
|                                |
|        SCREEN x of 4           |
|                                |
----------------------------------
|                                |
|        Back   Next    Cancel   |
----------------------------------

The wizard will build a profile of information as the user completes each screen. I have defined a Profile type that implements INotifyPropertyChanged that will contain the information the user provides. So far, so good.

My question is: When the first user control (Screen 1 of 4) modifies the Profile type, how do I alert the Window? I'm trying to use MVVM and not use code-behind.

I tried setting up an event on the first user control. The window would be the subscriber to that event, but that's not working.

Is there a better approach for a user control to alert the main window that something has happened?

2
Based upon what you wrote, the 'golden' standard is to bind the various buttons to commands in your view-model. Once the relevant command is executed, the view-model can use the event aggregator to broadcast the info to all interested components. - Gayot Fow

2 Answers

0
votes

MVVM uses Commands instead of Click handlers. So you should have an implementation of ICommand interface ready to use or you can get it from any MVVM oriented Framework

If you want to keep things simple, here is the link how to use commands

0
votes

What MVVM framework are you using? Most of them have an implementation of the Mediator pattern to handle communication between view models.

I use Cinch V2 and here you can find an explanation of how it implements the pattern and also see some code showing how to use it.

If you are not using a specific MVVM framework take the ideas from the implementation above and apply to you code!