Xamarin forms win phone silverlight 8.1 Toast notifications not working

195 views Asked by At

I am trying to make a toast notification show in a Xamarin Forms, windows phone 8.1 silverlight project. Inside the Windows Phone project I have a method that creates a toast notification, however, nothing happens when it is executed. No error is thrown everything seems to execute correctly but nothing happens on the phone.

I have tested it on an emulator and an actual cell phone. Everything I have found online until now is practically the same as what I have (with slight differences, but nothing that should make a difference).

The code in the method is the following:

private void CreateNotification(string title, string message)
{
    ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));

    ToastNotification toast = new ToastNotification(toastXml);
    toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(5);

    toastNotifier.Show(toast);
}

Any help would be greatly appreciated.

Thanks in advance!

1

There are 1 answers

1
Adam On BEST ANSWER

If you are using Xamarin Forms there is a NuGet package: https://www.nuget.org/packages/Toasts.Forms.Plugin/

It doesn't use the standard toast notification system in windows phone though as it needed to expand beyond it.

As for showing Toast Notifications have you set Toast Capable to Yes in your Package.appxmanifest?