缺少 Windows.UI.Notifications [英] Windows.UI.Notifications is missing

查看:18
本文介绍了缺少 Windows.UI.Notifications的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从

  1. 我尝试重新安装 .Net(我使用的是 4.5.2)
  2. 已安装 Windows 10 SDK
  3. 尝试使用全局导入
  4. 已添加

<块引用>

<TargetPlatformVersion>10.0</TargetPlatformVersion></PropertyGroup>

  1. 添加了 System.Runtime.dll 参考

可能对您无用的示例代码:

使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Text;使用 System.Threading.Tasks;使用 Microsoft.Toolkit.Uwp.Notifications;使用 Microsoft.QueryStringDotNET;使用 Windows.UI.Notifications;命名空间 MessagerClient.Notifications {类 DefaultWindowsNotification {公共静态无效通知测试(){string title = "安德鲁给你发了一张照片";string content = "看看这个,犹他州的快乐峡谷!";string image = "http://blogs.msdn.com/something.jpg";string logo = "ms-appdata:///local/Andrew.jpg";ToastVisual 视觉 = 新 ToastVisual() {BindingGeneric = 新 ToastBindingGeneric() {儿童 ={新的自适应文本(){文字 = 标题},新的自适应文本(){文字 = 内容},新的 AdaptiveImage(){来源 = 图像}},AppLogoOverride = 新 ToastGenericAppLogo() {来源 = 标志,HintCrop = ToastGenericAppLogoCrop.Circle}}};Console.WriteLine("通知");//不能使用,因为Windows.UI库ToastNotificationManager.CreateToastNotifier().Show(visual);}}}

解决方案

要在 Winforms 应用程序中使用这些 UWP 合同,您必须非常努力地与 Visual Studio 作斗争.你马上就因为错误的 TargetPlatformVersion 走错了路,很难从中恢复过来.要采取的完整步骤:

使用文本编辑器编辑 .csproj 文件,记事本即可.插入:

 <TargetPlatformVersion>10.0.10586</TargetPlatformVersion></PropertyGroup>

假设您的机器上安装了 10586 SDK 版本.目前,这些版本变化很快.通过查看 C:Program Files (x86)Windows Kits10Include with Explorer 仔细检查,您会看到该目录中列出的已安装版本.

打开 Winforms 项目,使用 Project > Add Reference > Windows tab > 勾选 Windows.DataWindows.UI 合同.再次添加引用并使用浏览选项卡选择 System.Runtime.我在 C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.6.1Facades 中选择了一个.此引用显示有警告图标,不确定它想说什么,但它似乎没有任何副作用.

通过在表单上放置一个按钮来测试它,双击添加 Click 事件处理程序.最基本的代码:

使用 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);}

通过使用不同的 ToastTemplateType 添加图像或多行文本来修饰.请记住,您的程序只能在 Win10 机器上运行.

I want to create simple toast notification to action center in windows 10 from this example. But I got problem on Step 2:

using Windows.UI.Notifications;

It`s missing. But I have spent a lot of time to find it and got no result. I really have no idea where I can find or at least download it.

What I tried:

  1. After long search I found Windows.UI.dll in C:WindowsSystem32 but when I try to add it as reference into project I got this error. Even after I tried to copy it and made this fully accessible nothing changed

  1. I tried to reinstall .Net (I`m 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 System.Runtime.dll reference

Example code which probably is 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);
        }
    }
}

解决方案

You have to fight Visual Studio pretty hard to use these UWP contracts in a Winforms app. You got off on the wrong foot right away with the wrong TargetPlatformVersion, pretty hard to recover from that. Full steps to take:

Edit the .csproj file with a text editor, Notepad will do. Insert this:

  <PropertyGroup>
       <TargetPlatformVersion>10.0.10586</TargetPlatformVersion>
  </PropertyGroup>

Which assumes you have the 10586 SDK version installed on your machine. Current right now, these versions change quickly. Double-check by looking in the C:Program Files (x86)Windows Kits10Include with Explorer, you see the installed versions listed in that directory.

Open the Winforms project, use Project > Add Reference > Windows tab > tick the Windows.Data and the Windows.UI contract. Add Reference again and use the Browse tab to select System.Runtime. I picked the one in C:Program Files (x86)Reference AssembliesMicrosoftFramework .NETFrameworkv4.6.1Facades. This reference displays with a warning icon, not sure what it is trying to say but it doesn't appear to have any side-effects.

Test it by dropping a button on the form, double-click to add the 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);
}

Embellish by using a different ToastTemplateType to add an image or more lines of text. Do keep in mind that your program can only work on a Win10 machine.

这篇关于缺少 Windows.UI.Notifications的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆