如何从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");
}
}
解决方案:将WPF
项目添加到Windows Application Packaging Project