禁用文本框时复选框时在C#中运行时未选中 [英] Disable text box when Check box is Unchecked during run time in C#

查看:144
本文介绍了禁用文本框时复选框时在C#中运行时未选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框和一个TextBox。在运行时,结果
如果复选框被选中,然后文本框被启用。



我就用下面的代码



 私人无效checkTime_Checked(对象做发件人,RoutedEventArgs E)
{
如果(checkTime.IsChecked ==真)
{
txtTime_SR.IsEnabled = TRUE;
}
}



我需要做的是,要禁用文本框当复选框运行期间未选中。



这样做呢?


解决方案

读您的文章和评论,我会想你正在做WPF或Silverlight。
然后,在这种情况下,你可能会做这一切在XAML:

 <复选框X:NAME = checkTime/> 
<文本框X:NAME =txtTime_SRIsEnabled ={结合器isChecked,的ElementName = checkTime,转换器= {StaticResource的NotConverter},模式=单向}/>



然后,你需要创建转换器。这可以通过在这里阅读后完成:如何绑定逆布尔属性WPF?



希望它能帮助


I have a CheckBox and a TextBox. During the runtime,
if the CheckBox is Checked then the TextBox is enabled.

I did it using following code

private void checkTime_Checked(object sender, RoutedEventArgs e)
{
    if (checkTime.IsChecked == true)
    {
        txtTime_SR.IsEnabled = true;
    }
}

What I need to do is, to disable the TextBox when the CheckBox is Unchecked during runtime.

Any idea of doing this ?

解决方案

Reading your post and comments, I'll guess you are doing WPF or silverlight. Then, in that case, you may do it all in XAML :

<CheckBox x:Name="checkTime" />
<TextBox x:Name="txtTime_SR" IsEnabled="{Binding IsChecked, ElementName=checkTime, Converter={StaticResource NotConverter}, Mode=OneWay}"/>

Then, you need to create the converter. This can be done by reading post here : How to bind inverse boolean properties in WPF?

Hope it helps

这篇关于禁用文本框时复选框时在C#中运行时未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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