【发布时间】:2018-06-20 21:41:49
【问题描述】:
大约六周前,我开发了一个 C# 控制台应用程序作为生成 Windows 10 toast 通知的概念证明。工作得很好。我重新访问该解决方案只是发现它构建并运行没有错误,但不再显示 toast 通知。对SO进行了彻底的研究,到目前为止还没有爱。希望社区中的某个人可以为我指明正确的方向,所以这里是:
环境
- Windows 10 版本 1709
- .NET 框架 4.6.1
- Visual Studio 2017,版本 15.7.4
.csproj 文件添加
<PropertyGroup>
<TargetPlatformVersion>10.0.1709</TargetPlatformVersion>
</PropertyGroup>
添加的参考文献
- Windows.Data
- Windows.UI
- System.Runtime(来自 .NETFramework\v4.6.1\Facades)
Program.cs
using System;
using System.IO;
using Microsoft.Toolkit.Uwp.Notifications;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
class Program
{
private const String APP_ID = "CompanyName.Notifier.ToastName";
static void Main(string[] args)
{
ToastContent content = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Desired text",
HintMaxLines = 1
},
new AdaptiveText()
{
Text = "More desired text"
},
},
HeroImage = new ToastGenericHeroImage()
{
Source = @"C:\Logo.png" // hard-coded path for testing
}
}
},
Duration = ToastDuration.Long
};
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(content.GetContent());
var tstVisual = new ToastNotification(xmlDoc);
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(tstVisual);
}
}
其他想法
我检查了 XML 的生成(使用content.GetContent() 获得的 XML 进行了File.WriteAllText)并且 toast XML 生成正常。似乎有什么东西阻止了 ToastNotificationManager.CreateToastNotifier 显示 toast 通知。感谢您查看此内容。
【问题讨论】:
-
您能否检查一下您的源代码控制系统并向我们展示最近对代码所做的任何更改?
content.GetContent()的值是多少? -
在
Main方法的末尾添加Console.ReadLine();有帮助吗? -
@mjwills 未对代码进行任何更改。该解决方案甚至没有检入 TFS(因为它是 POC)。
Console.ReadLine();没有影响。仅供参考,应用程序属性输出类型为Windows Application,以防止显示控制台窗口。 -
你试过在另一台机器上运行它吗?也许 Windows 10 安装了某种更新,而您却没有发现它破坏了您的代码。
-
@PaulSanders 我确实在另一台 Windows PC 上尝试过我的代码。没有销售。现在仍然有可能 Windows 更新确实占用了我的代码,但是我可以访问的所有 PC 都有相同的更新,我无权在我的公司桌面上回滚它们。
标签: c# windows winapi console-application toast