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.