This project is read-only.

Checkbox click

Oct 13, 2010 at 2:49 PM

In one of our edit window we use a ValueLine of type boolean. This results in a checkbox as expected. Now we want to add some functionality to the click event for this checkbox.

However this seems not possible. The checkbox itself does not respond to mouse clicks. The corresponding label does. How can we let the checkbox react to changes ?

Oct 14, 2010 at 10:48 AM
Edited Oct 14, 2010 at 10:58 AM

ValueLines are great when you don't care about the control inside (CheckBox) but whenever u need to change one of the entities inside it gets in the middle.

Its too 'astronautic' to expose abstract properties and events that work for TextBox, NumericTextBox, ComboBox, CheckBox or whatever control the end user defined for some specific data type. 


* After the ValueLine is Loaded, ValueLine.ValueControl property has the instance of the CheckBox on it. In that moment u can attach an event in code-behind. 

* On the main entity control, attach an event to DataContextChange and then in there to PropertyChanged so u know when the binded value has changed: 

InitializeComponents(); this.DataContextChanged += new DependencyPropertyChangedEventHandler(Entity_DataContextChanged); void Entity_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e){ if(e.NewValue != null) { var entity = ((MyEntityDN)e.Entity) entity.PropertyChanged -= Entity_PropertyChanged; entity.PropertyChanged += Entity_PropertyChanged; } } void Entity_PropertyChanged(object sender, PropertyChangedEventArgs e) { MyEntityDN cuestionario = sender as MyEntityDN; if(e.PropertyName =="MyBoolProperty") { //your code here } }

* Remove the ValueLine all together and put the checkbox manually, Rembember to:
1.- Bind correctly with ValidatesOnExceptions, ValidatesOnDataErrors, and NotifyOnValidationError.
2.- Put the PropertyInfo.NiceName() in the label if u want automatic nice names and localization support.  

Hope it helps,