Created
November 25, 2018 03:00
-
-
Save juucustodio/38148a50988626623ac06579359bc4df to your computer and use it in GitHub Desktop.
Example of how to use MessagingCenter in Xamarin.Forms applications. - https://julianocustodio.com/messagingcenter
This file contains 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 Android.App; | |
using Android.Widget; | |
using Android.Content.PM; | |
using Android.OS; | |
using Xamarin.Forms; | |
namespace DemoMessagingCenter.Droid | |
{ | |
[Activity(Label = "DemoMessagingCenter", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] | |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | |
{ | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
TabLayoutResource = Resource.Layout.Tabbar; | |
ToolbarResource = Resource.Layout.Toolbar; | |
MessagingCenter.Subscribe<Message>(this, "AddItem", message => { | |
ShowAlert("Item adicionado"); | |
}); | |
base.OnCreate(savedInstanceState); | |
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); | |
LoadApplication(new App()); | |
} | |
public void ShowAlert(string message) | |
{ | |
Toast.MakeText(ApplicationContext, message, ToastLength.Long).Show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment