How to implement text as HyperLink in Toast windows using xml?

Abboju, Mounika (CW) 1 Reputation point
2022-09-09T20:36:32.443+00:00

I am trying to implement the Hyperlink in windows toast which accepts xml as a string as per the documents i couldn't find a way to implement hyperlink in text
Example:
I need to display a text in toast as: To get more details. click here

here the click here should work as a link which opens a page in browser.

Note: it accepts only XML link to follow:https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml#text-elements

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
    2022-09-12T03:19:31.377+00:00

    Hello,

    Welcome to Microsoft Q&A!

    How to implement text as HyperLink in Toast windows using xml?

    I've checked the document and the sample about sending toast notification. It seems that adding HyperLink is not supported in the toast notification. Another thing is that, when click the Toast notification, the click event should be handled by the app not a different browser.

    My suggestion is that you could handle the activation in your app when the user click on the toast notification. Then you could navigate to a new page and use a WebView to show the link as you want. So you don't need to launch a broswer instead.

    Like this:

            protected override void OnActivated(IActivatedEventArgs args)  
            {  
      
                Frame rootFrame = Window.Current.Content as Frame;  
                // Handle notification activation  
                if (args is ToastNotificationActivatedEventArgs toastActivationArgs)  
                {  
                    // Obtain the arguments from the notification  
                    ToastArguments argument = ToastArguments.Parse(toastActivationArgs.Argument);  
      
                    // Obtain any user input (text boxes, menu selections) from the notification  
                    ValueSet userInput = toastActivationArgs.UserInput;  
      
                    // TODO: Show the corresponding content  
      
                    rootFrame.Navigate(typeof(TargetPage));  
                }  
      
                // Ensure the current window is active  
                Window.Current.Activate();  
            }  
      
    

    Or if you still want to use the browser of you system, you could also launch the default broswer for your UWP app via Launcher.LaunchUriAsync

    For more information about handling the activation of the toast notification, please check: Send a local toast notification from C# apps

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments