Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. MVVM > Communicating between different ViewModels

Communicating between different ViewModels

Applies to Silverlight 3, 4, 5 and WP7

Often, you'll find yourself in need of sending messages between ViewModels. A very typical example would be: you've got a View with a ListBox, and once an item is selected, you want that item to be displayed in detail in another View. In other words, the standard master-detail requirement.

How do you achieve this with MVVM? If you didn't follow the pattern, you could easily say: "well, I need to execute a method on ViewModel B when something happens in ViewModel A, so I'll keep a reference to ViewModel B in ViewModel A, so I can call the method when appropriate". This, of course, is tight coupling—your ViewModels aren't independent of each other anymore, and ViewModel A now knows that ViewModel B exists. What's more: if ViewModel B is removed, or heavily changed somehow, you'll need to update ViewModel A as well.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint