复选框错误隐藏文本框 [英] Checkbox false hide textbox

查看:108
本文介绍了复选框错误隐藏文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个简单的问题,但是我已经离开编程界三年了,所以请帮忙!

如果我在WPF页面上有一个复选框,如果未选中该复选框,如何隐藏文本框?

在此先感谢

I know this is an easy question, but I have been out of the programming world for 3 years so please help!

If I have a checkbox on a WPF Page how do I hide a textbox if the checkbox is not ticked?

Thanks in advance

推荐答案

嘿,

您可以将Textbox的Visibility属性绑定到CheckBox的Checked属性,并使用BooleanToVisibilityConverter来使类型匹配.那应该做.
让我知道是否需要进一步说明.
Hey,

You can bind the Textbox''s Visibility property to the CheckBox''s Checked property and use a BooleanToVisibilityConverter to make the types match. That should do it.
Let me know if you need more clarity.


好,这是一个示例窗口,其中包含了我认为您要的内容.当您单击复选框时,该文本块将变为可见.


< Window x:Class ="WpfFrontEnd.Window4"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
Title ="Window4" Height ="300" Width ="300">
< Window.Resources>

< BooleanToVisibilityConverter x:Key ="boolToVisible"/>

</Window.Resources>
< Grid>

< StackPanel>
< CheckBox x:Name ="CheckBox1"/>
< TextBlock Visibility ="{Binding ElementName = CheckBox1,Path = IsChecked,Converter = {StaticResource boolToVisible}}">你好</TextBlock>
</StackPanel>

</Grid>
</Window>
Ok here is a sample window with what I think you are asking for. When you click the checkbox, the textblock becomes visible.


<Window x:Class="WpfFrontEnd.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window4" Height="300" Width="300">
<Window.Resources>

<BooleanToVisibilityConverter x:Key="boolToVisible"/>

</Window.Resources>
<Grid>

<StackPanel>
<CheckBox x:Name="CheckBox1"/>
<TextBlock Visibility="{Binding ElementName=CheckBox1, Path=IsChecked, Converter={StaticResource boolToVisible}}">Hello</TextBlock>
</StackPanel>

</Grid>
</Window>


这篇关于复选框错误隐藏文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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