steam3d
steam3d

Reputation: 197

Access to Windows notification from WPF

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");
        }
    }

Upvotes: 2

Views: 822

Answers (1)

steam3d
steam3d

Reputation: 197

Solution: Add WPF project to Windows Application Packaging Project

Upvotes: 2

Related Questions