How make toast notification keep display until user click on it?

aluzi liu 486 Reputation points
2023-03-07T08:38:35.71+00:00

I am using the Microsoft.Toolkit.Uwp.Notifications package to display toast notification on my WPF project in windows10

I found that the toast will only shows for 6-7 seconds and then disappears, I want him keep display until user interact on it, I try this:

            var builder = new ToastContentBuilder()
                .AddArgument("Action", "NewToast")
                .AddArgument("ActionData", url);

//The documentation says set scenario to "reminder" will keep the toast display, but not work at all..
//And the "ExpirationTime" property is also not working...
            builder.SetToastScenario(ToastScenario.Reminder);
            builder.AddText(sFrom + " " + date.Substring(11, 5) + " " + windowTitle)
            .AddText(title)
            .AddText(idea)
            .Show(toast =>
            {
                toast.ExpirationTime = DateTime.Now.AddHours(8);
            });

So what's the right way to keep it display?

Developer technologies Universal Windows Platform (UWP)
Developer technologies Windows Presentation Foundation
Developer technologies .NET Other
Developer technologies C#
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2023-03-08T08:08:45.43+00:00

    @aluzi liu , Welcome to Microsoft Q&A, based on my test, I reproduced your problem when using ToastScenario.Reminder.

    There are two methods to let toast notification keep display until user click on it.

    First method, we need to add a button to the ToastContentBuilder, like the following code:

     var builder = new ToastContentBuilder()
                   .AddArgument("Action", "NewToast")
                   .AddArgument("ActionData", "");
    
                //The documentation says set scenario to "reminder" will keep the toast display, but not work at all..
                //And the "ExpirationTime" property is also not working...
                builder.SetToastScenario(ToastScenario.Reminder);
      
                builder.AddText("2023-03-08")
                .AddText("test1")
                 .AddButton(new ToastButton()
            .SetContent("Text reply"))
                .AddText("My Idead")
                .Show();
    
    

    You could refer to the Microsoft Learning Reminders, which has the following description:

    You must provide at least one button on your app notification. Otherwise, the notification will be treated as a normal notification.

    Therefore, we have to add a button in the ToastContentBuilder.

    Second method, you could also useToastScenario.IncomingCall directly without adding the button.

    Please try the following code:

     builder.SetToastScenario(ToastScenario.IncomingCall);
    
    

    Based on my test, after I used the above two methods, the toast notification will keep displaying until you click it.

    Hope my solution could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.