mvvm-toolkit-messenger

Implements decoupled pub/sub messaging between ViewModels using CommunityToolkit.Mvvm Messenger.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill mvvm-toolkit-messenger
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mvvm-toolkit-messenger
Source: https://github.com/github/awesome-copilot/tree/main/skills/mvvm-toolkit-messenger
Command: npx skills add https://github.com/github/awesome-copilot --skill mvvm-toolkit-messenger

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

ViewModels in MVVM applications often need to communicate without holding direct references to each other, and manual event wiring creates tight coupling, memory leaks, and hard-to-diagnose lifetime bugs. This Skill provides correct patterns for the CommunityToolkit.Mvvm Messenger so messages are delivered reliably without leaking recipients.

Core Features & Use Cases

  • Messenger Selection Guidance: Choose between WeakReferenceMessenger, StrongReferenceMessenger, and custom IMessenger instances based on lifetime and performance needs.
  • Full Messaging Patterns: Covers message definition, lambda and IRecipient<T> registration, channel tokens, request/reply with RequestMessage<T>, AsyncRequestMessage<T>, and CollectionRequestMessage<T>.
  • Lifecycle & Pitfall Diagnosis: Explains ObservableRecipient activation, explicit unregistration, and common bugs like closure-captured this, inherited message types, and cross-thread UI updates.
  • Use Case: In a WinUI 3 app, a settings ViewModel broadcasts a ThemeChangedMessage via WeakReferenceMessenger.Default, and multiple page ViewModels registered as IRecipient<ThemeChangedMessage> update their appearance without referencing the settings ViewModel.

Quick Start

Ask the AI to show how to send a message between two ViewModels using CommunityToolkit.Mvvm WeakReferenceMessenger with proper registration and unregistration.

Frequently Asked Questions about mvvm-toolkit-messenger

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I send messages between ViewModels in CommunityToolkit.Mvvm?

Define a message class, register a recipient with WeakReferenceMessenger.Default.Register using a static lambda, and call WeakReferenceMessenger.Default.Send with the message instance. Recipients react without holding references to the sender.

What is the difference between WeakReferenceMessenger and StrongReferenceMessenger?

WeakReferenceMessenger holds recipients weakly so they remain eligible for garbage collection even while registered, making it the default choice. StrongReferenceMessenger pins recipients until you call Unregister, which suits hot paths but leaks memory if you forget to unregister.

Does CommunityToolkit.Mvvm Messenger work with WinUI 3 and .NET MAUI?

Yes, the Messenger works across WPF, WinUI 3, .NET MAUI, Uno Platform, and Avalonia since it is part of the platform-agnostic CommunityToolkit.Mvvm 8.x package. UI-thread marshalling must be handled manually in handlers that update the interface.

Why is my Messenger handler never firing?

Common causes include registering on a different IMessenger instance than the sender, registering for a base message type while sending a derived type, or ObservableRecipient IsActive never being set to true so OnActivated never runs. Channel-scoped recipients also miss messages sent without a token.

How do I request a value back from another ViewModel using Messenger?

Define a class inheriting RequestMessage<T> or AsyncRequestMessage<T>, register a recipient that calls m.Reply with the value, and send the request message. Check HasReceivedResponse before reading Response to avoid exceptions when no recipient replied.