Well, what would you expect? You totally ignore the checked event on
radioButton1
(and never leave auto-generated names, they violate (good) Microsoft naming condition, always rename to some semantically sensitive names).
Here is how it can be resolved:
public partial class MyCustRadio : UserControl {
public MyCustRadio {
radioButton1.CheckedChanged += (sender, eventArgs) => {
if (this.CheckedChanged != null)
this.CheckedChanged.Invoke(this, new eventArgs);
}
}
public event System.EventHandler CheckedChanged;
public bool IsChecked {
get { return radioButton1.IsChecked; }
set { radioButton1.IsChecked = value; }
}
}
Are you getting the picture?
[EDIT]
With multiple radio buttons in one parent control (but how else?), you should not have this property. You can have, say:
byte CheckedRadioButton {
get { return this.chechedRadioButton; }
set {
System.Diagnostics.Debug.Assert(value <= checkBoxes.Length);
checkBoxes[value].Checked = true;
}
}
In the event handler (added for the event
CheckedChanged
for every radio button in its group, add the code to set the value of
this.chechedRadioButton
to the index of the radio button which has been just checked.
—SA