tags:

views:

173

answers:

1

Hi, I have a listbox control. I have created a ItemTemplate for this listbox which has two controls within it.

  1. Toggle Button
  2. Listbox Control

Structure

Basically the Listbox2 is a CheckedListbox. My requirement is as follows 1. Bind the ToggleButton to Listbox1 SelectedItem.i.e if 4 item is selected in Listbox1 then the togglebutton of 4th item should get checked automatically and other togglebutton should get unchecked. 2. If the ToggleButton is checked then All Checkboxes in Listbox2 should automatically selected. Also if one of the checkboxe s in Listbox2 is unselected then ToogleButton should get unchecked automatically. (This functionality is similar to TreeNode and childnode functionality. If parentnode is checked then all childnodes get selected and if one of the childnode is unselected parentnode should get unselected).

Can you please help me out in doing this.

A: 

Sample code will help us understand your problem better.

Looks like you are trying to add some business logic on to the UI, Try creating proper ViewModel and then Bind it to the control so that the calculations can be done at the ViewModel side and based on your logic you can update the UI- (INotifyPropertyChanged)

The ViewModel will be having a Bool property(Bind to ToggleButton) which changes according to the other 3 bool(which binds to the 4 Checkboxes). At any setter call inside the ViewModel has to recalculate(It will be a boolean AND operation) the entire Properties again. Since CheckBox binding mode is defaulted to TwoWay, it will be very easy to implement.

Jobi Joy