Skip to content

Instantly share code, notes, and snippets.

@Driv4r
Created June 14, 2016 23:55
Show Gist options
  • Save Driv4r/b82dec31f8e10495d6f2de62ab85ee4e to your computer and use it in GitHub Desktop.
Save Driv4r/b82dec31f8e10495d6f2de62ab85ee4e to your computer and use it in GitHub Desktop.
Simple Xamarin MessagingCenter example.
//Without sending arguments
//Subscribe
MessagingCenter.Subscribe<object> (this, "Arrived", (sender) => {
// do something whenever the "Arrived" message is sent from whatever type
//<object> is.
});
//Send
//All subscribers to "Arrived" of type "this" will be notified.
MessagingCenter.Send<object> (this, "Arrived");
//Unsubscribe
MessagingCenter.Unsubscribe<object> (this, "Arrived");
//With sending arguments.
//Subscribe
MessagingCenter.Subscribe<object, string> (this, "Arrived", (sender, string) => {
// do something whenever the "Arrived" message is sent from whatever type
//<object> is.
myEntry.Text = string;
});
//Send
//All subscribers to "Arrived" of type "this" will be notified.
MessagingCenter.Send<object, string> (this, "Arrived", "New String");
//Unsubscribe
MessagingCenter.Unsubscribe<object, string> (this, "Arrived");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment