I use mvvm in my application. So I have isChecked binded to the ViewModel property. The checkboxes are enabled.
When I click on a checkbox the tree automatically updates several layers, which is expected.
Each value on the tree works like a filter on the observable collection. So I have to recalculate it on every change.
But I don't want to do it on every call of Set method for isChecked property.
Is there a way get a callback/event when the tree finishes its own updates? So I rebuild final collection after all the checkboxes were set/reset.
Thanks
Hello Alexis,
I have been investigating into your requirement to conduct an action on check or uncheck of a checkbox in the XamDataTree, and it certainly makes sense that you do not want to consistently do this action for every checkbox that may be checked for a particular parent checkbox. Unfortunately, there is no event that fires after the checkboxes finish being recursively checked on the XamDataTree.
Rather than trying to handle this after the checkboxes are checked, though, I would recommend instead handling it before they are. What I mean by this is that the CheckboxSettings of the XamDataTree have a CheckboxStyle property that you can set. Using this property, you can define a Style that hooks into the PreviewMouseDown event of the Checkboxes on your node so that you can catch the click on the node’s checkbox. This style would look something along the lines of the following:
<ig:CheckBoxSettings.CheckBoxStyle> <Style TargetType="{x:Type CheckBox}"> <EventSetter Event="PreviewMouseDown" Handler="CheckBox_PreviewMouseDown" /> </Style> </ig:CheckBoxSettings.CheckBoxStyle>
Once this event is hooked, you can use the DataContext of the Checkbox, which will be a XamDataTreeNodeDataContext object to get either the Node or the underlying Data item for the node that the checkbox is attached to. You can then recursively loop through the child nodes / data items and construct your filter once on the basis of what the value of the checkbox will be for the parent node. Note, if you use the PreviewMouseDown event for this, this value will be the reverse of the Checkbox.IsChecked property, since the Checkbox will not have actually been checked yet.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Andrew,
When I defined the EventSetter in this way, it overrides CheckBox style. How can I preserve it?
Usually I use BasedOn property, But what should I use here? I do not use any theme, everything is by default.
Hi Andrew,
This approach may work.
However it brings some complexity.
First, I have to set CheckBoxMode to "manual" and do all the check/uncheck myself, which is doable but it's sad to abandon existing feature of XamDataTree.
Second, if I handle this event, the base class event handler is not called, so a checkbox remains unchanged.
Could you verify if the order of events on mouse click is correct
1. PreviewMouseDown
2. MouseDown
3. Click (exists?)
3. Checkbox changes it's status
4. Checked event
4. Binded isChecked property is updated
5. Recursively all other necessary checkboxes are updated
6. Is there anything else here? I'm still looking for a way to catch the time when XamDataTree finalizes its updates
Thank you Andrew.
I will try this approach tomorrow.