Search code examples
notificationsxamarin.androidxamarin.formsrenderer

XMessageControl UIMessage not working on monodroid


I am trying to change the way notifications are shown on my Xamarin.forms project and when adding the Softweb.Controls.UIMessage component it won't show either the message or toast.

UIMessage.ShowMessage ("Customization", "Hey! You Clicked on Button", MessageControl.MessageTypes.Warning, "red.png", Color.BrandRed, Color.Black, true, OnDissmissControl);

I running this code from a dependency controller, I was wondering if the error is caused by not having the right context, but I see not way to add one to the class. Has anyone try using this component on a Xamarin.forms project? (this is specific to MonoDroid).


Solution

  • The answer, just make sure you are running on the mainthread and it should work. This would have been much easier if the library had some documentation worth looking at.

        [assembly: Xamarin.Forms.Dependency (typeof (.Android.MessageBar))]
    namespace .Android
    {
        public class MessageBar : IMessageBar
        {
            public MessageBar ()
            {
            }
    
            public void Show(MessageType messageType, string title, string message)
            {
                var context = Forms.Context;
    
                Device.BeginInvokeOnMainThread (() => {
                    //CustomToast customtoast=new CustomToast(context, messageType, title, message);
                    UIMessage.ShowMessage ("Customization", "Hey! You Clicked on Button", MessageControl.MessageTypes.Warning, "validation.png", Color.BrandRed, Color.Black, true, OnDissmissControl);
    
                });
    
    
            }
            public void OnDissmissControl()
            {
    
            }
        }
    }