【发布时间】:2021-03-16 15:03:06
【问题描述】:
如何从 WPF 获得对 Windows 通知的访问权限?
我试过这种方式。我得到了accessStatus 允许。
但我得到了例外
System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)
这是我的代码:
using Windows.UI.Notifications.Management;
***
public partial class NotificationWindow : Window
{
UserNotificationListener listener;
public NotificationWindow()
{
InitializeComponent();
SubscribeToNotif();
}
public async void SubscribeToNotif()
{
listener = UserNotificationListener.Current;
UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();
if(accessStatus == UserNotificationListenerAccessStatus.Allowed)
listener.NotificationChanged += Listener_NotificationChanged;
}
private void Listener_NotificationChanged(UserNotificationListener sender, Windows.UI.Notifications.UserNotificationChangedEventArgs args)
{
Console.WriteLine("Got notif");
}
}
【问题讨论】:
标签: c# wpf windows notifications