This test from MSDN samples works for me with WinUI 3 and Microsoft.Toolkit.Uwp.Notifications
(I had to change the logo to an existing file) :
{
ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompat_OnActivated;
var toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Matt sent you a friend request"
},
new AdaptiveText()
{
Text = "Hey, wanna dress up as wizards and ride around on our hoverboards together?"
}
},
AppLogoOverride = new ToastGenericAppLogo()
{
//Source = "https://unsplash.it/64?image=1005",
//Source = "https://fastly.picsum.photos/id/1005/64/64.jpg?hmac=GfOyTHJcxsTTn0EXugyviiROYAqGAdDtqvf3zLOzwfA",
//Source = "ms-appx:///Assets/Butterfly.png",
Source = "E:\\Butterfly.png",
HintCrop = ToastGenericAppLogoCrop.Default
}
}
},
Actions = new ToastActionsCustom()
{
Buttons =
{
new ToastButton("Accept", "action=acceptFriendRequest&userId=49183")
{
ActivationType = ToastActivationType.Background
},
new ToastButton("Decline", "action=declineFriendRequest&userId=49183")
{
ActivationType = ToastActivationType.Background
}
}
},
Launch = "action=viewFriendRequest&userId=49183"
};
// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());
toastNotif.Activated += ToastNotif_Activated;
toastNotif.Failed += ToastNotif_Failed;
toastNotif.Dismissed += ToastNotif_Dismissed;
// And send the notification
ToastNotificationManagerCompat.CreateToastNotifier().Show(toastNotif);
}
private void ToastNotif_Dismissed(ToastNotification sender, ToastDismissedEventArgs args)
{
Console.Beep(2000, 10);
}
private void ToastNotif_Failed(ToastNotification sender, ToastFailedEventArgs args)
{
int i = 1;
// WPN_E_NOTIFICATION_TYPE_DISABLED
// HResult = -2143420140
//ErrorCode = { "Les paramètres empêchent la remise de ce type de notification. (0x803E0114)"}
}
private void ToastNotif_Activated(ToastNotification sender, object args)
{
Console.Beep(5000, 10);
}
private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e)
{
// Obtain the arguments from the notification
ToastArguments toastArgs = ToastArguments.Parse(e.Argument);
// Code...
}