Created
May 4, 2016 05:27
-
-
Save dennisroche/eb40794675dcd7a65258a3c40ba0490d to your computer and use it in GitHub Desktop.
Xamarin.Forms type-safe MessagingCenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Xamarin.Forms; | |
| // ReSharper disable CheckNamespace | |
| // Using global:: namespace | |
| public static class MessagingCenterEx | |
| { | |
| private class MessagingCenterSender | |
| { | |
| public static readonly MessagingCenterSender Instance = new MessagingCenterSender(); | |
| } | |
| public static void Send<TArgs> (TArgs args) | |
| { | |
| MessagingCenter.Send<MessagingCenterSender, TArgs>(MessagingCenterSender.Instance, string.Empty, args); | |
| } | |
| public static void Subscribe<TArgs> (object subscriber, Action<TArgs> received) | |
| { | |
| MessagingCenter.Subscribe<MessagingCenterSender, TArgs>(subscriber, string.Empty, (sender, args) => received(args)); | |
| } | |
| public static void Unsubscribe<TArgs> (object subscriber) | |
| { | |
| MessagingCenter.Unsubscribe<MessagingCenterSender, TArgs>(subscriber, string.Empty); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment