How to get access to Windows notification from WPF?
I tried this way. I got accessStatus
allowed.
But i get the exception
System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)
Here is my code:
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");
}
}
Solution:
Add WPF
project to Windows Application Packaging Project
User contributions licensed under CC BY-SA 3.0