R
R
rp_Faraon2022-03-25 20:07:46
Notifications
rp_Faraon, 2022-03-25 20:07:46

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();
                }
            };
        }

It's very strange that when I call to clear notifications, nothing changes. It is necessary that the application opens 1 time, regardless of how many notifications were sent. I searched on the Internet but did not find anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2022-03-28
@yarosroman

https://stackoverflow.com/questions/19147/what-is-...

D
Dyupich, 2022-04-20
@Dyupich

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 question

Ask a Question

731 491 924 answers to any question