Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

wpf - How to control the Visibility of a textbox with radio button "IsChecked" property?

How to control the Visibility of a textbox with radio button "IsChecked" property?

I have a Two textbox's let say txtbox1 and txtbox2 and I want to bind the visibily of both these textboxes based on the radio button IsChecked property. Below is the XAML code I am trying with:

<RadioButton
                x:Name="radioBtn"
                IsChecked="True"
                Margin="5"
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                Grid.Column="0">Enter Constant Values</RadioButton>

<TextBox Visibility="{Binding Path = IsChecked, ElementName = radioBtn}" />

Should I use Convertor ? Please help!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can use the built-in BooleanToVisibilityConverter.

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>
...
<TextBox Visibility="{Binding IsChecked,ElementName=radioBtn,Converter={StaticResource b2v}}" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...