編輯

共用方式為


WeakReferenceMessenger Class

Definition

A class providing a reference implementation for the IMessenger interface.

public sealed class WeakReferenceMessenger : Microsoft.Toolkit.Mvvm.Messaging.IMessenger
type WeakReferenceMessenger = class
    interface IMessenger
Public NotInheritable Class WeakReferenceMessenger
Implements IMessenger
Inheritance
WeakReferenceMessenger
Implements

Remarks

This IMessenger implementation uses weak references to track the registered recipients, so it is not necessary to manually unregister them when they're no longer needed.

The WeakReferenceMessenger type will automatically perform internal trimming when full GC collections are invoked, so calling Cleanup() manually is not necessary to ensure that on average the internal data structures are as trimmed and compact as possible. Note: this is not supported when running on .NET Framework, due to app domain unloading issues.

Constructors

WeakReferenceMessenger()

Initializes a new instance of the WeakReferenceMessenger class.

Properties

Default

Gets the default WeakReferenceMessenger instance.

Methods

Cleanup()

Performs a cleanup on the current messenger. Invoking this method does not unregister any of the currently registered recipient, and it can be used to perform cleanup operations such as trimming the internal data structures of a messenger implementation.

IsRegistered<TMessage,TToken>(Object, TToken)

Checks whether or not a given recipient has already been registered for a message.

Register<TRecipient,TMessage,TToken>(TRecipient, TToken, MessageHandler<TRecipient,TMessage>)

Registers a recipient for a given type of message.

Reset()

Resets the IMessenger instance and unregisters all the existing recipients.

Send<TMessage,TToken>(TMessage, TToken)

Sends a message of the specified type to all registered recipients.

Unregister<TMessage,TToken>(Object, TToken)

Unregisters a recipient from messages of a given type.

UnregisterAll(Object)

Unregisters a recipient from all registered messages.

UnregisterAll<TToken>(Object, TToken)

Unregisters a recipient from all messages on a specific channel.

Extension Methods

IsRegistered<TMessage>(IMessenger, Object)

Checks whether or not a given recipient has already been registered for a message.

Register<TMessage>(IMessenger, IRecipient<TMessage>)

Registers a recipient for a given type of message.

Register<TMessage>(IMessenger, Object, MessageHandler<Object,TMessage>)

Registers a recipient for a given type of message.

Register<TRecipient,TMessage>(IMessenger, TRecipient, MessageHandler<TRecipient,TMessage>)

Registers a recipient for a given type of message.

Register<TMessage,TToken>(IMessenger, IRecipient<TMessage>, TToken)

Registers a recipient for a given type of message.

Register<TMessage,TToken>(IMessenger, Object, TToken, MessageHandler<Object,TMessage>)

Registers a recipient for a given type of message.

RegisterAll(IMessenger, Object)

Registers all declared message handlers for a given recipient, using the default channel.

RegisterAll<TToken>(IMessenger, Object, TToken)

Registers all declared message handlers for a given recipient.

Send<TMessage>(IMessenger, TMessage)

Sends a message of the specified type to all registered recipients.

Send<TMessage>(IMessenger)

Sends a message of the specified type to all registered recipients.

Send<TMessage,TToken>(IMessenger, TToken)

Sends a message of the specified type to all registered recipients.

Unregister<TMessage>(IMessenger, Object)

Unregisters a recipient from messages of a given type.

Applies to