I am trying to relate the label text to the radio buttons value e.g. if radio is checked, then the label text is "x". If not, it's "y". In my XML:
<RadioButton x:Name="radio1" Content="Option1" GroupName="Group1" IsChecked="{Binding BoolValue, Converter={StaticResource BooleanConverter}, ConverterParameter='true', Mode=TwoWay}" />
<RadioButton Content="Option2" GroupName="Group2" IsChecked="{Binding BoolValue, Converter={StaticResource BooleanConverter}, ConverterParameter='false', Mode=TwoWay}"/>
...
...
<Label Content="{Binding LabelText, UpdateSourceTrigger=PropertyChanged}" Width="70"/>
In the code: (The _shape is bind to the radio button IsChecked;)
private bool _boolValue;
public bool BoolValue
{
get { return _boolValue; }
set
{
_boolValue= value;
PackLengthLabel = (_boolValue == true)? "x" : "y";
OnPropertyChanged("BoolValue");
}
}
And the label text property:
private string _labelText;
public string LabelText
{
get { return _labelText; }
set
{
_labelText = value;
OnPropertyChanged("LabelText");
}
}
The problem is that the changes don't affect the label text - it is the same all the time, no matter which checkbox is checked. The boolean value and the text value are changing (checked in the setters). I've also checked if the label is trying to get the _labelText from the getter but it doesn't. I also tried different binding modes, but the text was all the same. The only way it affects the other controls is by binding directly to the other properties e.g.:
IsEnabled="{Binding IsChecked, ElementName=radio1}"
Edit1:
I can get it working in two ways:
setting the label content value in the View code behind, refering to the elements properties
using the code here: https://stackoverflow.com/a/23642108/3974198
But I'm still curious, why the simple getter and setter of the label text value didn't do the job.