我想弄清楚是否有可能通过我的WPF应用程序访问Windows 10中存在的内置通知服务。 我正在使用VS 2015和c#。 另外,是toasternotification同样的事情?他们在Windows 10中看起来不再那样了。 如果是的话,您能否引导我以正确的方向来命名空间等?Windows 10通知WPF
是的,我已经在网上搜索,只有Win 7发现asasternotification。这不是我要找的东西。
谢谢
我想弄清楚是否有可能通过我的WPF应用程序访问Windows 10中存在的内置通知服务。 我正在使用VS 2015和c#。 另外,是toasternotification同样的事情?他们在Windows 10中看起来不再那样了。 如果是的话,您能否引导我以正确的方向来命名空间等?Windows 10通知WPF
是的,我已经在网上搜索,只有Win 7发现asasternotification。这不是我要找的东西。
谢谢
找到a code sample that is similar to what you need, but only does Toast Notifications。
您基本上想要一个引用Windows.UI组件的常规.NET应用程序。
要使用Windows 10通知你需要编辑的csproj文件并添加目标平台,
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>
一旦你这样做,你应该能够添加一个引用到Windows.UI组件。
右键单击References节点,然后单击左侧窗格中的Windows。 选中Windows.UI,Windows.Data和Windows.Foundation复选框。
接下来在您的表单类文件上,添加using Windows.UI.Notifications;
以访问ToastManager组件。
一旦你的,访问您要使用
// Get a toast XML template
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Content"));
Here are the different Toast type enumerations的模板。
一旦你有你需要创建一个ToastNotification并将其发送到ToastNotificationManager
// Create the toast and attach event listeners
var toast = new ToastNotification(toastXml);
toast.Activated += ToastActivated;
toast.Dismissed += ToastDismissed;
toast.Failed += ToastFailed;
// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier("My Toast").Show(toast);
您可以将所激发的,驳回和失败的事件处理程序的事件太吐司模板的引用。
我尝试在WPF应用程序中使用此提示。但是我找不到有关评论中提到的“AppUserModelId”的任何信息。 –
我真的不记得在这种情况下,AppUserModelID是否相关,它将使用当前用户来显示它,这被称为有很多关于它的微软网站的文档[here](https:// msdn。 microsoft.com/en-us/library/dd378459) –
是的,谢谢,我看到了这个文档。否则,上面的代码在我的WPF应用程序中不会导致异常,但没有通知:/ –
参见http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/08/quickstart-sending-a-local-toast-notification-and-handling-activations-from-it-windows- 10.aspx但我不知道它是否也适用于wpf或仅适用于UWP – Pazi01
请参阅https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from -win32-apps-in-windows-10/WPF/Win32 – k94ll13nn3