MessagingCenter 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
MessagingCenterMessagingCenter
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() MessagingCenter()

Creates a new MessagingCenter with default values.

Properties

Instance Instance

Gets the singleton instance of the MessagingCenter.

Methods

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

Sends a named message with the specified arguments.

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

Sends a named message that has no arguments.

Subscribe<TSender,TArgs>(Object, String, Action<TSender,TArgs>, TSender) 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) 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) Unsubscribe<TSender,TArgs>(Object, String)

Unsubscribes from the specified parameterless subscriber messages.

Unsubscribe<TSender>(Object, String) 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) 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) 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) 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) IMessagingCenter.Subscribe<TSender>(Object, String, Action<TSender>, TSender)

Subscribes to the specified message from the specified source.

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

Unsubscribes the specified subscriber from the specified message.

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

Unsubscribes the specified subscriber from the specified message.

Extension Methods

LoadFromXaml<TXaml>(TXaml, String) LoadFromXaml<TXaml>(TXaml, String)

Returns an initialized view by loading the specified xaml.

LoadFromXaml<TXaml>(TXaml, Type) LoadFromXaml<TXaml>(TXaml, Type)

Returns a TXaml with the properties that are defined in the application manifest for callingType.

Applies to