Windows.UI.Notifications丢失 [英] Windows.UI.Notifications is missing
问题描述
我想从
- 我尝试重新安装.Net(我使用4.5.2)
- 已安装Windows 10 SDK
- 试图与全局导入
- 已添加
< PropertyGroup>
< TargetPlatformVersion> 1.0< / TargetPlatformVersion>
< / PropertyGroup>
- 已添加
System.Runtime.dll
参考
示例代码可能对您没有用:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用Microsoft.Toolkit.Uwp.Notifications;
使用Microsoft.QueryStringDotNET;
使用Windows.UI.Notifications;
命名空间MessagerClient.Notifications {
class DefaultWindowsNotification {
public static void notificationTest(){
string title = Andrew向您发送了照片;
string content =检查一下,犹他州的快乐峡谷!;
string image = http://blogs.msdn.com/something.jpg;
string logo = ms-appdata:////local/Andrew.jpg;
ToastVisual visual =新ToastVisual(){
BindingGeneric =新ToastBindingGeneric(){
儿童=
{
新AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
新AdaptiveImage()
{
源=图片
}
},
AppLogoOverride = new ToastGenericAppLogo(){
来源=徽标,
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
};
Console.WriteLine( NOTIFICATION);
//由于Windows.UI库
而不能使用ToastNotificationManager.CreateToastNotifier()。Show(visual);
}
}
}
要在Winforms应用程序中使用这些UWP合同,就必须与Visual Studio进行激烈的斗争。您使用错误的TargetPlatformVersion立即走错了脚,很难恢复。采取的所有步骤:
使用文本编辑器编辑.csproj文件,记事本即可。插入以下内容:
< PropertyGroup>
< TargetPlatformVersion> 10.0.10586< / TargetPlatformVersion>
< / PropertyGroup>
假设您的计算机上安装了10586 SDK版本。目前,这些版本变化很快。通过在C:\Program Files(x86)\Windows Kits\10\Explorer中进行仔细检查,可以看到该目录中列出了已安装的版本。
打开Winforms项目,使用项目>添加引用> Windows选项卡>勾选 Windows.Data
和 Windows.UI
合同。再次添加引用,并使用浏览选项卡选择System.Runtime。我在C:\Program Files(x86)\参考程序集\Microsoft\Framework\.NETFramework\v4.6.1\Facades中选择了一个。该参考显示带有警告图标,不确定要说什么,但似乎没有任何副作用。
通过拖放按钮进行测试在窗体上,双击以添加Click事件处理程序。最基本的代码:
使用Windows.UI.Notifications;
...
private void button1_Click(对象发送者,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:
- After long search I found
Windows.UI.dll
inC:\Windows\System32
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
- I tried to reinstall .Net (I`m using 4.5.2)
- Installed Windows 10 SDK
- Tried to import with global
- Added
<PropertyGroup> <TargetPlatformVersion>10.0</TargetPlatformVersion> </PropertyGroup>
- 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 Kits\10\Include 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 Assemblies\Microsoft\Framework\ .NETFramework\v4.6.1\Facades. 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屋!