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.
I believe that the reason that you are not seeing the other events happen when placing a breakpoint in the PreviewMouseDown event is because the actual check-action happens on MouseUp. When the breakpoint is hit, the process of the MouseDown => MouseUp action is interrupted, as Visual Studio is focused and the MouseUp event will likely happen on the Visual Studio IDE. Knowing this, I now think it may be a better option to use the PreviewMouseUp event instead of PreviewMouseDown in this case.
Regarding the checkbox style being overridden, this is expected as WPF only keeps one local style for its elements. The style to base on exists in the generic.xaml file commonly found here:
C:\Program Files (x86)\Infragistics\<version>\WPF\DefaultStyles\DataTree
Inside this file, you will find a Style targeting a Checkbox with an x:Key of “cbStyle.” This is the Style you will need to include to use with the BasedOn property of your Checkbox style.
Please let me know if you have any other questions or concerns on this matter.
I do not believe it is possible to merge the generic.xaml dictionary by going through the DLL in that way. With that said, for your convenience I am attaching a ResourceDictionary including the Checkbox Style for the XamDataTree.
Please let me know if you any other questions or concerns on this matter.
DataTreeCheckboxDictionary.zip
Hello Andrew,
You're right about MouseUp/MouseDown events..
About that generic.xaml, we do not install Infragistics on our build server, so it does not have ProgramFiles folder with all those xamls. We use just dlls.
There is a way to link a style to another inside of dll using something like:
<Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Infragistics.WPF4.v192.2;component/generic.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources>
But I don't know the correct path to that generic xaml.