none
[UWP]How can i get the click event of notification from notification history? RRS feed

  • Question

  • How can i get the click event of notification from notification history

    Using 

    toastNotification.Activated += ToastNotification_Activated;

    but its not working when i click on notification popup from history


    Friday, September 13, 2019 12:57 PM

All replies

  • Hi,

    When you click on the body of the notification, in general it will activate the app. Do you mean you want to handle the activation of the app?

    If so, you need to use another way. When you app is in the foreground and you click the notification, the OnActivated is invoked instead of OnLaunched, with a new activation kind – ToastNotification. Thus, the developer is able to easily distinguish a toast activation and perform tasks accordingly. So you need to override the OnActivated event in the App.Xaml.cs.

    Like this:

       protected override void OnActivated(IActivatedEventArgs args)
            {
                // Get the root frame
                Frame rootFrame = Window.Current.Content as Frame;
    
                // TODO: Initialize root frame just like in OnLaunched
    
                // Handle toast activation
                if (args is ToastNotificationActivatedEventArgs)
                {
                    var toastActivationArgs = args as ToastNotificationActivatedEventArgs;
    
                    // Parse the query string (using QueryString.NET)
                    QueryString e = QueryString.Parse(toastActivationArgs.Argument);
                }
    
                // TODO: Handle other types of activation
    
                // Ensure the current window is active
                Window.Current.Activate();
            }
    This is a very simple one that just used to activate the app. You could do more things as you want.

    Please refer this document for more information about how to handle the activation for your app:Activation handling.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 6:36 AM
    Moderator