Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable text box when Check box is Unchecked during run time in C#

Tags:

c#

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 ?

like image 827
Zarco Avatar asked Oct 30 '12 08:10

Zarco


1 Answers

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

like image 174
Kek Avatar answered Nov 15 '22 05:11

Kek