binding text on radiobutton selection

I have a WPF form that contains 2 radiobutton and one label. I need to change label text depending on radiobutton selection

<RadioButton IsChecked="True">
        <TextBlock Text="First"/> 
</RadioButton>
<RadioButton>
        <TextBlock Text="Second"/>
</RadioButton>

And label as the text block

<TextBlock  Text=""/>

What is the better way to bind TextBlock Text property on radiobutton selection?


You could use an Enum property that would hold a value indicating which RadioButton is currently checked. Then the same field would be used in a converter to return the text you want.


well the best would be to bind isChecked to a property and text to another property

<RadioButton Content = "First" IsChecked="{Binding Value1}"/>
<RadioButton Content = "Second" IsChecked="{Binding Value2}"/>
<TextBlock Text="{Binding MyText}"/>

then when property is set change text

链接地址: http://www.djcxy.com/p/7766.html

上一篇: UWP ListView将SelectedItem绑定到viewmodel中的属性

下一篇: 在单选按钮选择上绑定文本