Missing Windows.UI.

I want to create a simple toast notification in the action center in Windows 10 from in this example . But in step 2, I had a problem:

using Windows.UI.Notifications; 

It is gone. But I spent a lot of time to find it and did not get any result. I really don't know where I can find or at least download it.

What I tried:

  • After a long search, I found Windows.UI.dll in C:\Windows\System32 , but when I try to add it as a link to the project, I got this error. Even after I tried to copy it and made it fully accessible, nothing has changed.

enter image description here

  1. I tried reinstalling .Net (I am using 4.5.2)
  2. Installed Windows 10 SDK
  3. Tried to import with global
  4. Added
 <PropertyGroup> <TargetPlatformVersion>10.0</TargetPlatformVersion> </PropertyGroup> 
  1. Added link System.Runtime.dll

Sample code that is probably useless for you:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Uwp.Notifications; using Microsoft.QueryStringDotNET; using Windows.UI.Notifications; namespace MessagerClient.Notifications { class DefaultWindowsNotification { public static void notificationTest() { string title = "Andrew sent you a picture"; string content = "Check this out, Happy Canyon in Utah!"; string image = "http://blogs.msdn.com/something.jpg"; string logo = "ms-appdata:///local/Andrew.jpg"; ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image } }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } } }; Console.WriteLine("NOTIFICATION"); //Can`t use because of Windows.UI library ToastNotificationManager.CreateToastNotifier().Show(visual); } } } 
+9
c # winforms
source share
2 answers

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.

+16
source share

If someone accidentally stumbles upon this, check out this similar but newer post -

Toast notifications in Win Forms.NET 4.5

Read Stepan Hakobyan's comment below.

In fact, I see the same thing. This code is executed, I can step through it without exception, but a notification about the toast is never shown.

0
source share

All Articles