Xamarin.Forms Guides | Samples

Xamarin.Forms.MessagingCenter Class

Associates a callback on subscribers with a specific message name.

See Also: MessagingCenter

Syntax

public static class MessagingCenter

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 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.