Search code examples
windows-phone-8windows-phonewindows-phone-8.1

How to show a floating message in windows phone (Android Toasts)


How can I implement the behaviour of an Android Toast, that is, a floating message that is auto dismissed after some seconds without requiring a user interaction?

enter image description here

Thanks


Solution

  • In Windows Phone there are toasts available. They can be showed on demand or be scheduled. They are shown at the top of the screen and dissapear after a while. A sample toast showed on demand can look like this:

    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
    XmlNodeList textElements = toastXml.GetElementsByTagName("text");
    textElements[0].AppendChild(toastXml.CreateTextNode("MyApp"));
    textElements[1].AppendChild(toastXml.CreateTextNode("Message"));
    ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
    

    You will find more information at MSDN.

    NOTE that the code above is for WP8.1 RunTime and Universal apps. If you are looking for Silverlight example, take a look st ShellToast and tutorial at MSDN.