Binding a TextBlock to a Radio Button

Slabs1960

Member
Joined
Mar 19, 2017
Messages
19
Programming Experience
10+
I would like to Hide/ Display text in a TextBlock depending on the Checked Status of a Radio Button. But I cannot get it to work. Any advice is welcome.

Radio Button Code:
VB.NET:
     <StackPanel Grid.Column="0" Grid.Row="0" Margin="8,0,0,5">
                                <RadioButton Content="mA to PV"
                                             GroupName="select_conversion_type"
                                             x:Name="mA_to_PV_Radio_Button"
                                             Click="MA_to_PV_Radio_Button_Click"
                                             Cursor="Hand"/>
                            </StackPanel>
Text Block Code
VB.NET:
   <
                    <TextBlock Text="Text 01"
                               FontSize="12"
                               TextWrapping="Wrap"
                               Margin="5, 0, 0, 0"
                                Visibility="{Binding         
                                ➥ElementName=mA_to_PV_Radio_Button, Path=mA_to_PV_Radio_Button.IsChecked}"/>
Error is a the ElementName.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,100
Location
Sydney, Australia
Programming Experience
10+
I've never tried it but, if you have set ElementName to mA_to_PV_Radio_Button then wouldn't Path be just IsChecked?
 

Slabs1960

Member
Joined
Mar 19, 2017
Messages
19
Programming Experience
10+
I solved the problem using a Boolean conversion:
VB.NET:
    <!--Radio Button IsChecked to Boolean Conversion -->
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="RadioButtonVisibilty" />
    </Window.Resources>
VB.NET:
<TextBlock
                                            FontSize="13"
                                            HorizontalAlignment="Center"
                                            TextWrapping="Wrap"
                                            Margin="5, 0, 0, 0"
                                            Visibility="{Binding IsChecked,ElementName=mA_to_PV_Radio_Button,
                                                        Converter={StaticResource RadioButtonVisibilty}}"                               
                                          
                                            <Italic>PV = ((mA - 4)/ 16) * (PV<Span FontSize="10">max</Span> -
                                        PV<Span FontSize="10">min</Span>)) + PV<Span FontSize="10">min</Span></Italic>
  

                                </TextBlock>
The first piece of code is used in the Visibility Property of the second piece of code.
 
Last edited:
Top Bottom