Xamarin.Forms Guides | Samples

Xamarin.Forms.MessagingCenter Class

Associates a callback on subscribers with a specific message name.

See Also: MessagingCenter

Syntax

public class MessagingCenter : IMessagingCenter

Remarks

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

C# Example

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);

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.MessagingCenter are listed below.

See Also: Object

Public Constructors

Creates a new MessagingCenter with default values.

Public Properties

[read-only]
static
InstanceIMessagingCenter. Gets the singleton instance of the MessagingCenter.

Public Methods

static
Send<TSender>(TSender, String)
Sends a named message that has no arguments.
static
Send<TSender,TArgs>(TSender, String, TArgs)
Sends a named message with the specified arguments.
static
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.
static
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.
static
Unsubscribe<TSender>(Object, String)
Unsubscribes a subscriber from the specified messages that come from the specified sender.
static
Unsubscribe<TSender,TArgs>(Object, String)
Unsubscribes from the specified parameterless subscriber messages.

Explicitly Implemented Interface Members

MessagingCenter$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.
MessagingCenter$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.
MessagingCenter$IMessagingCenter.Subscribe<TSender,TArgs>(Object,String,Action<TSender,TArgs>,TSender)Subscribes to the specified message from the specified source.
MessagingCenter$IMessagingCenter.Subscribe<TSender>(Object,String,Action<TSender>,TSender)Subscribes to the specified message from the specified source.
MessagingCenter$IMessagingCenter.Unsubscribe<TSender,TArgs>(Object,String)Unsubscribes the specified subscriber from the specified message.
MessagingCenter$IMessagingCenter.Unsubscribe<TSender>(Object,String)Unsubscribes the specified subscriber from the specified message.