mvvm light - messaging

2019-06-16 08:43发布

问题:

I'm curently teaching myself the MVVM pattern. I've hit my first snag with the concept of messaging. I know messaging is contained in the mvvm-light toolkit. But I cannot find an example of usage anywhere (no sample projects are provided in the download).

If anyone can direct me to some information as to how to use messaging in that toolkit, that would be ace.

Thanks

回答1:

I found the following article on the subject. The subject line seems a little unrelated but that link is for part 2 of the article and if you read and scroll down a bit you will find info on the RelayCommand, Messenger, EventToCommand, and ICleanup.

http://www.codeproject.com/KB/silverlight/IssueVisionSilverlightPt2.aspx

Good luck.



回答2:

I have posted an example of using Messaging here, as part of my Intro to MVVM Light series.

My goal in this example is to send a message indicating that navigation is needed. The VM can't manage the navigation so it sends a message to the view. We do this in three steps:

  1. Create a class to contain the message that is to be passed
  2. In the view model, instantiate the message class and broadcast the message
  3. Within MainPage.xaml.cs register for the message and handle it when received

The complete source code is posted and also available for download.



回答3:

http://blog.galasoft.ch/archive/2009/09/27/mvvm-light-toolkit-messenger-v2-beta.aspx

Here abit about it.

/Bo



回答4:

I posted some simple MVVM Light messaging code on this other question with sample compiled code and explanations.

Send a empty Message or Notification with MVVM toolkit light

Cheers, Mario



标签: mvvm-light