Skip to content

Instantly share code, notes, and snippets.

@k94ll13nn3
Last active December 3, 2021 13:21
Show Gist options
  • Save k94ll13nn3/f3dce111e525a02c2bc9 to your computer and use it in GitHub Desktop.
Save k94ll13nn3/f3dce111e525a02c2bc9 to your computer and use it in GitHub Desktop.
Basic c# console app for showing a toast notification.
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace ToastDesktop
{
internal class Program
{
/// You have to add in the .csproj:
/// <TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
/// I always put it in the <PropertyGroup/> which contains the <TargetFrameworkVersion/>.
///
/// References to add :
/// - Windows.UI
/// - Windows.Data
private static void Main(string[] args)
{
string xml = $@"
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Some title</text>
<text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text>
</binding>
</visual>
</toast>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
ToastNotification toast = new ToastNotification(doc);
toast.Tag = "tag";
toast.Group = "group";
ToastNotificationManager.CreateToastNotifier("ToastDesktop").Show(toast);
}
}
}
@icalvo
Copy link

icalvo commented Feb 25, 2016

For this to work with Windows 10 you must add a reference to: C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment