C# 缺少Windows.UI.Notifications
我想从创建到windows 10中操作中心的简单toast通知。但我在第二步遇到了问题:C# 缺少Windows.UI.Notifications,c#,winforms,C#,Winforms,我想从创建到windows 10中操作中心的简单toast通知。但我在第二步遇到了问题: using Windows.UI.Notifications; 它不见了。但我花了很多时间去寻找,却没有结果。我真的不知道在哪里可以找到或者至少下载它 我尝试的是: 经过长时间的搜索,我在C:\Windows\System32中找到了Windows.UI.dll,但当我试图将它作为引用添加到项目中时,我遇到了这个错误。即使在我试图复制它并使其完全可访问之后,也没有任何改变 我试图重新安装.Net(我使用
using Windows.UI.Notifications;
它不见了。但我花了很多时间去寻找,却没有结果。我真的不知道在哪里可以找到或者至少下载它
我尝试的是:
C:\Windows\System32
中找到了Windows.UI.dll
,但当我试图将它作为引用添加到项目中时,我遇到了这个错误。即使在我试图复制它并使其完全可访问之后,也没有任何改变要在Winforms应用程序中使用这些UWP合同,您必须非常努力地与Visual Studio抗争。你用了错误的TargetPlatformVersion马上就走错了路,很难从中恢复过来。采取的全部步骤: 用文本编辑器编辑.csproj文件,记事本就可以了。插入以下内容:
<PropertyGroup>
<TargetPlatformVersion>10.0.10586</TargetPlatformVersion>
</PropertyGroup>
通过使用不同的ToastTemplateType添加一个图像或多行文本来进行修饰。请记住,您的程序只能在Win10机器上运行。如果有人碰巧发现了这一点,请参阅这篇类似但较新的文章- 阅读底部Stepan Hakobyan的评论
基本上,我也看到了同样的事情。这段代码运行时,我可以逐行检查,没有例外,但toast通知从未在表单应用程序中显示。可能会对您有所帮助。我没有使用Project>Add Reference>Windows选项卡>勾选Windows.Data和Windows.UI合同。在那之后,它起作用了,该死的,我太坏了-
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);
}
}
}
<PropertyGroup>
<TargetPlatformVersion>10.0.10586</TargetPlatformVersion>
</PropertyGroup>
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);
}