Does WinUI 3 have the feature to add desktop notifications?
See reference (see below)
Does WinUI 3 have the feature to add desktop notifications?
See reference (see below)
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.
Reference: