如何使用单选按钮"IsChecked"控制文本框的可见性?财产? [英] How to control the Visibility of a textbox with radio button "IsChecked" property?

查看:80
本文介绍了如何使用单选按钮"IsChecked"控制文本框的可见性?财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单选按钮"IsChecked"属性控制文本框的可见性?

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

我有两个文本框,假设txtbox1和txtbox2,并且我想根据单选按钮IsChecked属性绑定这两个文本框.以下是我尝试使用的XAML代码:

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}" />

我应该使用Convertor吗?请帮忙!

Should I use Convertor ? Please help!!

推荐答案

是的,您可以使用内置的

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}}" />

这篇关于如何使用单选按钮"IsChecked"控制文本框的可见性?财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆