---
title: "Checkbox isEnabled behaviour unable to figure out"  
description: "Checkbox isEnabled behaviour unable to figure out"  
author: "Royce Roy"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1494/checkbox-isenabled-behaviour-unable-to-figure-out  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Checkbox isEnabled behaviour unable to figure out

Hi guys

I have three [CheckBox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) in my WPF [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and what I want is to [disable](https://www.mindstick.com/forum/12901/how-to-disable-enable-input-box-in-aspx-with-value-from-sql)/ Enable the CheckBoxes according to a [Property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) in [ViewModel](https://www.mindstick.com/forum/157215/what-is-viewmodel-in-mvc).\

```
<Grid>    <CheckBox x:Name="cbTest1" Margin="12,341,476,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />    <CheckBox x:Name="cbTest3" Margin="74,341,414,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay }" />    <CheckBox x:Name="cbTest2" Margin="131,341,359,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay }" />    <Button x:Name="btnClick" Click="btnClick_Click" Margin="231,333,29,5" /></Grid>In my testing application I have written a code behind for button clickprivate void btnClick_Click(object sender, RoutedEventArgs e)    {        if (_boolProperty == true)        {            _boolProperty = false;            cbTest1.IsEnabled = false;        }        else        {            _boolProperty = true;            cbTest1.IsEnabled = true;        }    }
```

The weird [behavior](https://www.mindstick.com/forum/159354/runtimeexception-and-exception-behavior) is that if I comment the cbTest1.IsEnabled = false; or cbTest1.IsEnabled = true; then the CheckBox es remain as disabled,

but changes in only one CheckBox say, "cbTest1"'s [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) to true also make changes in the other checkBoxes as well. Like if cbTest1.IsEnabled = true; then all three CheckBox are enabled. if cbTest1.IsEnabled = false; then all three CheckBox are disabled.

Anybody can [enlighten me](https://answers.mindstick.com/qa/37702/could-someone-enlighten-me-on-the-loop-quantum-gravity-theory) please. Why is this happening? How does [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) happening here? One more [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time), how do I go for binding of the checkBoxes isEnabled Property with a property in viewModel?

## Replies

### Reply by Pravesh Singh

Hi Royce,

<CheckBox x:Name="cbTest1" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay}" />

<CheckBox x:Name="cbTest3" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay}" />

<CheckBox x:Name="cbTest2" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay}" />

All three check boxes bind to the same source, so no matter what you do, they will always share the same state. Furthermore, your binding is a two-way binding, so setting IsEnabled manually for one checkbox will make the underlying property you bound to change too which will then again trigger the other two checkboxes to update.

If you want to have separate states, you will have to use three different properties to bind to.

how do I go for binding of the checkBoxes isEnabled Property with a property in viewModel?

What you did is already correct (minus the shared property). So if you bind to BoolProperty1, BoolProperty2 and BoolProperty3 and each of those properties exists in your view model, then everything is good to go. All you need to make sure then is that the checkboxes have the view model as their data context. This is usually achieved by giving a parent component (often the Window itself) the data context:

Window window = new MyWindow();

window.DataContext = new MyViewModel();

window.Show();


---

Original Source: https://www.mindstick.com/forum/1494/checkbox-isenabled-behaviour-unable-to-figure-out

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
