Access to Windows notification from WPF

0

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");
        }
    }
c#
wpf
windows
notifications
asked on Stack Overflow Mar 16, 2021 by steam3d

1 Answer

0

Solution: Add WPF project to Windows Application Packaging Project

answered on Stack Overflow Mar 19, 2021 by steam3d

User contributions licensed under CC BY-SA 3.0