I have several RadioButtons combined in one Group so that only one can be checked. The RadioButtons are bound to boolean Properties.
This works very well and my program reacts on the changes of these Properties.
Suppose optA is selected. Next I select optB, the value of PropertyB is set to true and my program reacts accordingly. However, at this time both optA and optB are true until the Group of Radio buttons updates optA to false which again triggers my “IsSelected” event.
I think this is totally correct behavior…
But how can I distinguish between a change from the user and the automated change from the group?
Edit: Code
<RadioButton Name="featureCheckBox" GroupName="featureRadioButtonGroup" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" />
public bool IsSelected {
get{ return _isSelected; }
set { PropertyChanged.ChangeAndNotify(ref _isSelected, value, () => IsSelected); }
}
First of all to answer your question.
Change the set portion of the IsSelected property as follows. (You will of course have to write the actual code for the if statement)
You could instead just listen for false values but then you’d have to set an arbitrary options to true to begin with. Or you could just listen for true values and ignore all false values which means you will have problems with multiple Properties being true until the group box updates the old option to false.
Now for the advice.
A much better model would be this.
but do NOT group them. (Grouping them causes the UI to force the selection of only one. This does not lend itself to separation of UI and business logic.)Several benefits of doing it this way.
ANYcode.)