【发布时间】:2021-06-30 16:28:51
【问题描述】:
我正在使用 UWP API 开发 C# WinForms 应用程序。我正在尝试以编程方式阅读通知,到目前为止我已经成功了。但是,每当我从 UserNotification 类调用 AppInfo 时,我都会收到 NotImplementedException,无论我从 AppInfo 读取什么属性。
有人有什么建议吗?
我只能找到这个问题的 1 个答案,它不是很有用,而且也有几年的历史了。这是我项目中的主要障碍,非常感谢任何帮助!
提前谢谢你。
编辑
这是我的代码。
try {
this.source = notification.AppInfo.DisplayInfo.DisplayName;
} catch(NotImplementedException e) {
this.source = "Unspecified";
}
NotificationBinding binding = notification.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
if (binding != null) {
Console.WriteLine(binding.GetTextElements()[1]);
this.title = binding.GetTextElements().FirstOrDefault()?.Text;
this.body = string.Join("\n", binding.GetTextElements().Skip(1).Select(t => t.Text));
}
Init();
我正在使用来自the examples in the docs.的代码
【问题讨论】:
-
请发布您的代码。您很可能需要将包含
NotImplementedException的行替换为一些实际代码(或将其注释掉)。 -
就像我说的,我正在使用 UWP API。它可以很好地读取通知,我不确定如果异常不是由我的代码特别引起的,我将如何处理它。