[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Collapse]Build an Application
  [Expand]Choose Application UI
  [Expand]Printing and Exporting
  [Collapse]WinForms MVVM
     Conventions and Attributes
     Data Bindings and Notifications
     Layer Communication. Messenger
     Fluent API Support
     View Management
     ViewModel Management
   [Expand]Design-time Support
  [Expand]Right-to-Left Layout
   Redistribution and Deployment
   How to: Perform Actions On Application Startup
 [Expand]Controls and Libraries
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Layer Communication. Messenger


MVVM Best Practices Demo The text below has a related example in the DevExpress 'MVVM Best Practices' demo.

Group: API Code Examples

Module: Messenger

Example: Messenger

19.1 Demo Center: Launch the demo

Your real-life applications will almost always have multiple Views and ViewModels. And, with rare exceptions,you will need a way for these separate layers to communicate with each other and share data. To solve this task, use the DevExpress MVVM Messenger.

The idea of this message mechanism is very simple: in the sender ViewModel, you call the Send method to transmit required data as a message. In the recipient ViewModel, the Register method is called to catch all messages.

The Register method establishes a permanent connection between your ViewModels. This means once called, the Register method does not need to be called ever again - all consequent messages sent will be received automatically. To break this connection, use the Unregister method.

If there are multiple senders that transmit messages of the same type, you can use tokens to label messages sent from different senders. Tokens can be objects of any type, the code below uses simple string tokens.

The Register and Unregister methods have corresponding overloads that allow you to receive or block messages marked with the specific token.

Is this topic helpful?​​​​​​​