I want to change content of clicked button in C# WinForms Toast Notification.
Here are my codes:
private void ButtonAction(ToastNotification sender, object args)
{
ToastActivatedEventArgs taeaTıklananDüğme = args as ToastActivatedEventArgs;
switch(taeaTıklananDüğme.Arguments)
{
case "Gates":
MessageBox.Show("Button has been clicked!");
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
var BildiriminOzellikleri = new ToastContentBuilder()
//.AddArgument("action", "viewConversation")
//.AddArgument("conversationId", 9813)
.AddAppLogoOverride(new Uri("C:\Users\StackOverFlow\Desktop\EkranResmi_07112024105204.png")) // Bildirimin sol üst köşesinde görünecek olan logo
.AddButton(new ToastButton("Bill", "Gates")
.SetContent("MyButton")
)
.AddInlineImage(new Uri("D:\İndirilenler\Images\d033c77c3960090e00c0d4aa9408ef45.jpeg")) // Yazıların altında görünecek olan resim
.AddInputTextBox("tbGosterilecekMesajiYazmaKutusu", placeHolderContent: "Please enter a text here.")
.AddText("Hello World!") // İlk "AddText" fonksiyonu kalın harflerle başlık yazmaya yazar
.AddText("This is a text.") // Diğer "AddText" fonksiyonu ise başlığın altına açıklama, metin vs. yazılmasını sağlar
.AddText("This is an another text.")
.AddVisualChild(new AdaptiveProgressBar()
{
Status = new BindableString("pbProgressBarStatus"),
Title = new BindableString("pbProgressBarTitle"),
Value = new BindableProgressBarValue("pbProgressBarValue"),
ValueStringOverride = new BindableString("pbProgressBarValueString")
}
)
.SetToastDuration(ToastDuration.Long)
.GetToastContent();
var Bildirim = new ToastNotification(BildiriminOzellikleri.GetXml());
Bildirim.Activated += ButtonAction;
Bildirim.Group = "NotificationGroup";
Bildirim.Tag = "NotificationTag";
Bildirim.Data = new NotificationData();
Bildirim.Data.Values["pbProgressBarStatus"] = "Downloading...";
Bildirim.Data.Values["pbProgressBarTitle"] = "StackOverFlow.rar";
Bildirim.Data.Values["pbProgressBarValue"] = "0.1";
Bildirim.Data.Values["pbProgressBarValueString"] = "1%";
ToastNotificationManager.CreateToastNotifier("cagatay").Show(Bildirim);
}
Here is the screenshoot of my notification:
https://i.sstatic.net/pB8dCE7f.png
How can I change “MyButton” text to another thing when the button is clicked?
2
Is button1 just a normal windows forms button? Text is just a property of the control.
If it is, try doing:
button1.Text = "New Text";
Add that to your button1_Click event.
private void button1_Click(object sender, EventArgs e)
{
button1.Text = "New Text";
var BildiriminOzellikleri = new ToastContentBuilder()
qater is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
probably the easiest way would be to hold the button in a class variable, create it at the beginning and pass the object into the method:
ToastButton buttonToChange;
private void button1_Click(object sender, EventArgs e)
{
buttonToChange = new ToastButton("Bill", "Gates").SetContent("MyButton");
var BildiriminOzellikleri = new ToastContentBuilder()
.AddAppLogoOverride(new Uri("C:\Users\StackOverFlow\Desktop\EkranResmi_07112024105204.png")) // Bildirimin sol üst köşesinde görünecek olan logo
.AddButton(buttonToChange)) ....
and when the button is clicked call the SetContent
method again:
private void ButtonAction(ToastNotification sender, object args)
{
buttonToChange.SetContent("new content");
}