Messaging between Views and ViewModles with Simple MVVM Toolkit

Aug 24, 2011 at 9:47 PM

With Simple MVVM Toolkit is it possible to send/receive messages between code behind classes of a View and ViewModels?

I would like to be able to send a message from my ViewModel to code behind of a MainWindow and open a new Window from there passing the MainWindow as a parent...

Thanks.

Aug 25, 2011 at 8:44 AM

Hi netizenk

I'm not sure about the specifics of your request but the following links might prove useful:

I'm looking at navigation between different pages myself at the moment so if you get chance to elaborate your high level requirement maybe myself or someone else might be able to point you in the right direction.

Cheers - Graham

Coordinator
Aug 25, 2011 at 5:06 PM
The way to pass a message between a ViewModel and the corresponding View is:
a) Expose an event on the ViewModel, which is an EventHandler<NotificationEventArgs>
b) Call the Notify method in the ViewModel, passing the event and a NotificationEventArgs (which can pass data as well as a callback).
c) In the View's code behind, subscribe to the event in the ViewModel

If you want to communicate between two ViewModels, or between Views, or between a ViewModel and some other class, you can use the Message Bus.

Cheers,
Tony

>
Aug 25, 2011 at 5:14 PM
Hi Graham,

Thanks a lot for the links will check them out... my high level requirement is simple, I don't want to open new windows from the ViewModel but from the code behind of the MainWindow so that I can pass it as a parent to these new windows that I am opening...

Dean

On Thu, Aug 25, 2011 at 1:44 AM, GrahamDSmith <notifications@codeplex.com> wrote:

From: GrahamDSmith

Hi netizenk

I'm not sure about the specifics of your request but the following links might prove useful:

I'm looking at navigation between different pages myself at the moment so if you get chance to elaborate your high level requirement maybe myself or someone else might be able to point you in the right direction.

Cheers - Graham

Read the full discussion online.

To add a post to this discussion, reply to this email (simplemvvmtoolkit@discussions.codeplex.com)

To start a new discussion for this project, email simplemvvmtoolkit@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
"The fundamental cause of trouble in the world today is that the stupid are cocksure while the intelligent are full of doubt."

Bertrand Russell
Aug 25, 2011 at 8:34 PM

Is it possible to pass more than one parameter from one ViewModel to another ViewModel using the message bus or do you need to concatenate the string and then parse it back out on the secondary VM? I have a scenario where I need to pass two parameters from one Page/ViewModel to a secondary Page/ViewModel -  objectID and type (both string values). I was curious to learn if anyone has tried (or if it is possible) to pass more than one parameter through navigation and the message bus service.

thank you

Aug 25, 2011 at 9:53 PM

@rlcrews

Not sure about passing multiple params but you can always pass a Tuple containing as many params as you like...

Aug 26, 2011 at 12:10 PM

 

Thanks netizenk,!