4

Does WinUI 3 have the feature to add desktop notifications?

See reference (see below)

Desktop Notification

2
  • Did you look into: github.com/CommunityToolkit/WindowsCommunityToolkit and their toast notification? Commented Aug 11, 2022 at 13:50
  • Thank you, I will look into it and if there are any problems I will get in touch with you. Commented Aug 11, 2022 at 13:57

2 Answers 2

9

Use build-in AppNotification class:

// using Microsoft.Windows.AppNotifications;

public static bool SendNotificationToast(string title, string message)
{
    var xmlPayload = new string($@"
        <toast>    
            <visual>    
                <binding template=""ToastGeneric"">    
                    <text>{title}</text>
                    <text>{message}</text>    
                </binding>
            </visual>  
        </toast>");

    var toast = new AppNotification(xmlPayload);
    AppNotificationManager.Default.Show(toast);
    return toast.Id != 0;
}

Update 2023-03-12

Since Windows App SDK 1.2 You can use AppNotificationBuilder class.

public static bool SendNotificationToast(string title, string message)
{
    var toast = new AppNotificationBuilder()
        .AddText(title)
        .AddText(message)
        .BuildNotification();

    AppNotificationManager.Default.Show(toast);
    return toast.Id != 0;
}

More advanced examples are available at Microsoft Learn.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Install the Nuget package:
    • Microsoft.Toolkit.Uwp.Notifications
  2. Use 'ToastContentBuilder' to build the notification content.
  3. Handling activation
    • After showing a notification, you will likely need to handle the user clicking the notification. Whether that means bringing up specific content after the user clicks it, opening your app in general, or performing an action when the user clicks the notification.

Reference:

Microsoft Docs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.