How to create a Toast in C# for Metro apps on Windows 8

The documentation that Microsoft provides for creating toasts is far more complicated and confusing then it really needs to be. The sample app for Toast Notifications runs over 20 files and multiple projects, yet the good news is that it is actually quite simple. The basics can be demonstrated in less then 10 lines. This is primarily done by writing the toast’s xml structure by hand as a string.

string title = "TITLE";
string message = "toast details";
string imgURL = "ms-appx:///Assets/Logo.png";

string toastXmlString = "<toast><visual version='1'><binding template='toastImageAndText02'><text id='1'>"+title+"</text><text id='2'>"+message+"</text><image id='1' src='" + imgURL + "'/></binding></visual></toast>";

Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
toastDOM.LoadXml(toastXmlString);
ToastNotification toast = new Windows.UI.Notifications.ToastNotification(toastDOM);
ToastNotifier toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);