Answer the question
In order to leave comments, you need to log in
How to fix the processing of all notifications by pressing a button on one of them?
I need an application to be opened by pressing a button on a notification, but when I create several notifications and press the button on one of them, several applications are launched, depending on how many notifications I created.
private void Button_click(object sender, RoutedEventArgs e)
{
new ToastContentBuilder()
.AddArgument("action", "1")
.AddText("Уведомление")
.AddText("Уведомление")
.AddButton(new ToastButton()
.SetContent("Перейти к уведомлению")
.AddArgument("action", "2"))
.Show();
ToastNotificationManagerCompat.OnActivated += toastArgs =>
{
if (toastArgs.Argument.ToString() == "action=2")
{
Process.Start("какое-то приложение");
ToastNotificationManagerCompat.History.Clear();
}
};
}
Answer the question
In order to leave comments, you need to log in
It can be done as follows by putting the processing method only in the Load of your form.
//Load WinForm method
private void MainWindow_Load(object sender, EventArgs e)
{
ToastNotificationManagerCompat.OnActivated += (toastArgs) =>
{
Process.Start("some application");
ToastNotificationManagerCompat.History.Clear();
};
}
// Method for calling Toast
private void MainWindowInfo_Click(object sender, EventArgs e)
{
new ToastContentBuilder()
.AddArgument("action", "1")
.AddText("Notification")
.AddText("Notification")
.AddButton(new ToastButton()
.SetContent("Go to notification")
.AddArgument("action", "2"))
.Show();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question