次の方法で共有


MessagingCenter Class

Definition

Caution

We recommend migrating to CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger: https://www.nuget.org/packages/CommunityToolkit.Mvvm

Associates a callback on subscribers with a specific message name.

public ref class MessagingCenter : Microsoft::Maui::Controls::IMessagingCenter
[System.Obsolete("We recommend migrating to `CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger`: https://www.nuget.org/packages/CommunityToolkit.Mvvm")]
public class MessagingCenter : Microsoft.Maui.Controls.IMessagingCenter
[<System.Obsolete("We recommend migrating to `CommunityToolkit.Mvvm.Messaging.WeakReferenceMessenger`: https://www.nuget.org/packages/CommunityToolkit.Mvvm")>]
type MessagingCenter = class
    interface IMessagingCenter
Public Class MessagingCenter
Implements IMessagingCenter
Inheritance
MessagingCenter
Attributes
Implements

Remarks

The following shows a simple example of a strongly-typed callback using MessagingCenter is:

public class SubscriberThing 
{
	public int IntProperty { get; set; }
}

var subscriber = new SubscriberThing();
MessagingCenter.Subscribe<MyPage, int> (subscriber, "IntPropertyMessage", (s, e) => {
	subscriber.IntProperty = e; 
});

//...later...

MessagingCenter.Send<MyPage, int>(this, "IntPropertyMessage", 2);
Assert.AreEqual(2, subscriber.IntProperty);

Constructors

MessagingCenter()

Properties

Instance

Gets the singleton instance of the MessagingCenter.

Methods

Send<TSender,TArgs>(TSender, String, TArgs)
Send<TSender>(TSender, String)
Subscribe<TSender,TArgs>(Object, String, Action<TSender,TArgs>, TSender)
Subscribe<TSender>(Object, String, Action<TSender>, TSender)
Unsubscribe<TSender,TArgs>(Object, String)
Unsubscribe<TSender>(Object, String)

Explicit Interface Implementations

IMessagingCenter.Send<TSender,TArgs>(TSender, String, TArgs)
IMessagingCenter.Send<TSender>(TSender, String)
IMessagingCenter.Subscribe<TSender,TArgs>(Object, String, Action<TSender,TArgs>, TSender)
IMessagingCenter.Subscribe<TSender>(Object, String, Action<TSender>, TSender)
IMessagingCenter.Unsubscribe<TSender,TArgs>(Object, String)
IMessagingCenter.Unsubscribe<TSender>(Object, String)

Applies to