Click here to Skip to main content
15,884,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have problems handling/evaluating the user reaction (button pressed...) from a ToastNotification.

What I have tried:

Tried this code:

C#
ToastContentBuilder tcb = new ToastContentBuilder();
		tcb.AddArgument("action", "viewConversation");
		tcb.AddArgument("conversationId", 9813);
		tcb.AddText("Installation will be executed in 2 minutes");
		tcb.AddAppLogoOverride(new Uri(PROGRAM_PATH + "LDNotifyIcon.png"), ToastGenericAppLogoCrop.Circle);
		tcb.AddHeroImage(new Uri(PROGRAM_PATH + "LDNotifyHero.png"));
		tcb.AddToastInput(new ToastSelectionBox("time")
		{
			DefaultSelectionBoxItemId = "60",
			Items =
			 {
			new ToastSelectionBoxItem("1", "1 minute"),
			new ToastSelectionBoxItem("5", "5 minutes"),
			new ToastSelectionBoxItem("10", "10 minutes"),
			new ToastSelectionBoxItem("60", "1 hour"),
			new ToastSelectionBoxItem("240", "4 hours")
			//new ToastSelectionBoxItem("1440", "1 day")
			 }
		});
		tcb.AddButton(new ToastButton()
			.SetContent("Start now")
			.AddArgument("action", "startNow")
			.SetBackgroundActivation());
		tcb.AddButton(new ToastButton()
			.SetContent("Snooze")
			.AddArgument("action", "snooze")
			.SetBackgroundActivation());
		tcb.SetToastScenario(ToastScenario.Reminder);
		tcb.GetToastContent();
		toast = new ToastNotification(tcb.GetXml());
		toast.Activated += HandleToastActivation;
		toast.Tag = "RebootNotifier";
		ToastNotificationManager.CreateToastNotifier().Show(toast);
				
		private static void HandleToastActivation(ToastNotification sender, object args)
        {
            Log("HandleToastActivation reached"); // writing to Logfile
        }


The toast shows up, but when i press "Snooze", the void "HandleToastActivation" is never reached.

Alternatively i tried in the Startup function:

C#
ToastNotificationManagerCompat.OnActivated += toastArgs =>
        {
			// Obtain the arguments from the notification
			ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
			string strAction = args.Get("action");

			// Obtain any user input (text boxes, menu selections) from the notification
			ValueSet userInput = toastArgs.UserInput;
			userInput.TryGetValue("time", out object oTime);
			...
		}


Again.. the code lines are never reached.

I have a wpf application, included a packaging project, finally the project will be published as an MXIS Installation package file.

Could anyone please help me how i can get/handle the user input from the toast notification?
That would be great
Thanks a lot in advance !
Posted
Updated 3-Dec-21 23:11pm
v3
Comments
[no name] 3-Dec-21 14:21pm    
Use this app to help design adaptive live tiles and interactive toasts for Windows 10.

The app provides instant visual previews of your tile or toast while editing, similar to Visual Studio's XAML editor/design view. Your payload is also checked for errors, ensuring you create a valid payload.

https://www.microsoft.com/en-us/p/notifications-visualizer/9nblggh5xsl1?SilentAuth=1&wa=wsignin1.0&activetab=pivot:overviewtab
Emil12345687 4-Dec-21 6:19am    
Hi Gerry,
thank you! That would be an interesting solution if i would use it for me only.
But the project is for my company, and we cannot assume that thousands of users have to install this app first.
Best regards
Emanuel
[no name] 4-Dec-21 12:39pm    
It a "design tool". Nothing to do with the user or sending it out to thousands. I'm practically speechless.
Emil12345687 5-Jan-22 4:02am    
Sorry, didn't realize in that moment that only i as developer have to install it, not the users...
I tried to install, but Microsoft Store is blocked by our IT Policy...
Does this app also help to handle the events? The only problem i still have is that i cannot determine which button the user pressed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900