Hello,
Welcome to Microsoft Q&A!
This is a summary for the discussion in the comment. Hope this will help others who are facing the same issue.
The first thing is that make sure you've created a WinUI3 project with correct version. It is suggested to use Windows App SDK 1.5 or heigher and .NET 6 or higher.
You could follow the document https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=desktop-msix for implementing the notification feature.
Step1: Install the Microsoft.Toolkit.Uwp.Notifications
Nuget package
Step2: Add toast code in the default button click event.
new ToastContentBuilder()
.AddArgument("action", "viewConversation")
.AddArgument("conversationId", 9813)
.AddText("Andrew sent you a picture")
.AddText("Check this out, The Enchantments in Washington!")
.Show();
Step3: Change the manifest like the document. Make sure you've modified the GUID and app Executable. Don't forget to add declaration for xmlns:com and xmlns:desktop.
Step4: Add code to handle activation.
ToastNotificationManagerCompat.OnActivated += toastArgs =>
{
// Obtain the arguments from the notification
ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
// Obtain any user input (text boxes, menu selections) from the notification
ValueSet userInput = toastArgs.UserInput;
// Need to dispatch to UI thread if performing UI operations
Application.Current.Dispatcher.Invoke(delegate
{
// TODO: Show the corresponding content
MessageBox.Show("Toast activated. Args: " + toastArgs.Argument);
});
};
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.