You need to struggle with Visual Studio quite difficult to use these UWP contracts in a Winforms application. You got off the wrong foot right away with the wrong TargetPlatformVersion, it's pretty hard to recover from that. Complete steps:
Edit the .csproj file using a text editor that will make Notepad. Insert this:
<PropertyGroup> <TargetPlatformVersion>10.0.10586</TargetPlatformVersion> </PropertyGroup>
It is assumed that version 10586 SDK is installed on your computer. These versions are currently changing rapidly. Double check by looking in C: \ Program Files (x86) \ Windows Kits \ 10 \ Include with Explorer, you will see the installed versions listed in this directory.
Open the Winforms project, use Project> Add Link> Windows Tab> check the Windows.Data and Windows.UI contract. Add the link again and use the Browse tab to select System.Runtime. I selected one of the files C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.6.1 \ Facades. This link displays with a warning icon, not sure what it is trying to say, but it has no side effects.
Check this by clicking the button on the form, double-click to add a Click event handler. The most basic code:
using Windows.UI.Notifications; ... private void button1_Click(object sender, EventArgs e) { var xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); var text = xml.GetElementsByTagName("text"); text[0].AppendChild(xml.CreateTextNode("Hello world")); var toast = new ToastNotification(xml); ToastNotificationManager.CreateToastNotifier("anythinggoeshere").Show(toast); }
Decorate using another ToastTemplateType to add an image or multiple lines of text. Remember that your program can only run on a Win10 machine.
Hans passant
source share