radio.Checked += new RoutedEventHandler(VariantChecked);
assuming I have this code. What if I want to pass an argument to VariantChecked method. What syntax should I apply?
radio.Checked += new RoutedEventHandler(VariantChecked); assuming I have this code. What if I want to
Share
During creation, attach your data object to the DataContext or the Tag property of the RadioButton.
Then in the event handler, get the data back:
In the above example I have assumed that you have a class or struct named YourData that you want to provide. You can replace this through any primitive like string or int or any other object type.
The above works also from xaml:
Here I have taken the Tag property because it makes for such a construction more sense, but DataContext could also be taken. The event handler is the same except for casting from the Tag-property.
By the way, you can make the code more generic by not specify a concrete control-class but a base class:
Hope this helped…