Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to send Toast notifications from console application using ToastNotificationManager ?

I know that it is possible to send Toast notifications from Windows Universal app:

var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);

*doc - Toast stored in XML string

To use ToastNotificaionManager I need Windows.UI.Notifications library which I can't reference in console application project.

The library I mentionet before is actualy used by WinRT. Is it possible to use WinRT APIs in Windows console application ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
835 views
Welcome To Ask or Share your Answers For Others

1 Answer

At first you need to declare that your program will be using winRT libraries:

  1. Right-click on your yourProject, select Unload Project
  2. Right-click on your yourProject(unavailable) and click Edit yourProject.csproj
  3. Add a new property group:<targetplatformversion>8.0</targetplatformversion>
  4. Reload project
  5. Add reference Windows from Windows > Core
    enter image description here

Now you need to add this code:

using Windows.UI.Notifications;

and you will be able to send notifications using this code:

var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);

Reference: How to call WinRT APIs in Windows 8 from C# Desktop Applications - WinRT Diagram


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...