访问来自 WPF 的 Windows 通知
Access to Windows notification from WPF
如何从 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
如何从 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