Home > Back-end >  How to add an CheckedChanged or SelectedValueChaged event in a RadioButton
How to add an CheckedChanged or SelectedValueChaged event in a RadioButton

Time:04-10

Do you have any example or reference on how am I going to add an event to a new RadioButton object. So basically I created an RadioButton object in my ViewModel with properties.

var grid = new Grid();
grid.Children.Add(new RadioButton() 
{ 
   IsChecked = question.Answer != null && question.Answer.Value == qa.Value,
   IsEnabled = !this.IsReadOnly,
   GroupName = $"question-{question.OrderNum}",
}, 0, 0);

So with that I want to add the event of CheckedChaged or SelectedValueChanged so that I can save the selected value of the user from those RadioButton.

Thank you

CodePudding user response:

var grid = new Grid();

var radio = new RadioButton() 
{ 
   IsChecked = question.Answer != null && question.Answer.Value == qa.Value,
   IsEnabled = !this.IsReadOnly,
   GroupName = $"question-{question.OrderNum}",
};

radio.CheckedChanged  = myEventHandler;

grid.Children.Add(radio,0,0);
  • Related