Condividi tramite


MessagingCenter Class

Definition

Associates a callback on subscribers with a specific message name.

public class MessagingCenter : Xamarin.Forms.IMessagingCenter
type MessagingCenter = class
    interface IMessagingCenter
Inheritance
System.Object
MessagingCenter
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()

Creates a new MessagingCenter with default values.

Properties

Instance

Gets the singleton instance of the MessagingCenter.

Methods

Send<TSender,TArgs>(TSender, String, TArgs)

Sends a named message with the specified arguments.

Send<TSender>(TSender, String)

Sends a named message that has no arguments.

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

Run the callback on subscriber in response to parameterized messages that are named message and that are created by source.

Subscribe<TSender>(Object, String, Action<TSender>, TSender)

Run the callback on subscriber in response to messages that are named message and that are created by source.

Unsubscribe<TSender,TArgs>(Object, String)

Unsubscribes from the specified parameterless subscriber messages.

Unsubscribe<TSender>(Object, String)

Unsubscribes a subscriber from the specified messages that come from the specified sender.

Explicit Interface Implementations

IMessagingCenter.Send<TSender,TArgs>(TSender, String, TArgs)

Sends a message and arguments to objects that are listening for them on the type that is specified by TSender.

IMessagingCenter.Send<TSender>(TSender, String)

Sends the named parameterless message to objects that are listening for it on the type that is specified by TSender.

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

Subscribes to the specified message from the specified source.

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

Subscribes to the specified message from the specified source.

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

Unsubscribes the specified subscriber from the specified message.

IMessagingCenter.Unsubscribe<TSender>(Object, String)

Unsubscribes the specified subscriber from the specified message.

Applies to