Hi, I have couple of questions on XamDataTree with CheckBox:
1. Currently, we can only check/uncheck the checkbox when click on the checkbox, is there a way to click on item, checkbox will be auto checked?
2. Select state and MouseOver state only change background color of an item, checkbox isn't included, can you provide sample to also highlight checkbox background?
3. How to change the foreground color of selected item.
Thanks,
Crystal.
Hello Crystal,
After reviewing your questions I have created a sample project that illustrate how some of the functionality could be achieved. I am not sure if you would like to change the background of the checkbox itself or to the element where the checkbox is placed so there is no white space between the checkbox and the items name so I have not modified the default style. In both cases you can copy the style from the generic.xaml file located at C:\Program Files (x86)\Infragistics\2014.2\WPF\DefaultStyles\DataTree and modify it to meet your criteria.In order to modify the foreground color and the check state when a node is selected you can use SelectedNodesCollectionChanged event and modify the state and the foreground color.
Hi Maria, thank you for response and sample project. It's very helpful.
For setting selected item font color, I am trying to style xamDataTree following sample "Styling xamDataTree" in "Samples Browser" So the SelectedStates is set in code below
<VisualStateGroup x:Name="SelectedStates"> <VisualState x:Name="NotSelected"></VisualState> <VisualState x:Name="Selected"> <Storyboard> <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="SelectedBorder" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="00:00:00"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup>
Do you have sample code to show me how to set font color this way?
Thanks,Crystal.
Thank you for your feedback Crystal.I am glad that the approach did help you. If you have any other questions on the same, please feel free to ask.
Hi Maria,
I have another question, we need is to have checkboxes in XamDataTree reflects what's set in its ItemsSource.
I tried with binding CheckBoxMemberPath to a property in data layer. However, the checkbox in parent node isn't updated accordingly, when it's leaf node is checked. Do you know how to set parent node checkbox to be in sync with it's leaf node. please see attached sample project.
Hi Crystal,
This behavior is caused by the fact that the parent nodes are initialized first and then the children. When the tree is loaded this will set the check state of the parent to unchecked as it is not bound to a property with the corresponding value. Then when the check state of a child node is set through the binding the parent does not corresponds to it. In order to make sure that the parent states are validated after the children are bound you can call the ValidateParentCheckedState method. Here is a code snippet for the same. You can call the Loop method after the tree is loaded:
public void Loop()
{
Action<XamDataTreeNodesCollection> accessNodes = null;
accessNodes = (nodes) =>
foreach (var n in nodes)
if (n.Manager.ParentNode != null)
n.Manager.ParentNode.ValidateParentCheckedState();
}
accessNodes(n.Nodes);
};
accessNodes(tree.Nodes);
I hope this will be helpful for you. Please let me know if you have any other questions.
Hi Maria, thank you for looking into this. when should I call this loop method. I tried to call it in Loaded event handler. it doesn't work.
Crystal
Calling the Loop method in the loaded event of the tree is working on my side. I have attached the modified sample. Though it may be a timing issue that is causing the behavior on your side so that not all nodes are rendered. You can use a dispatcher in this case to change the priority of the Loop call to Backgroud. Let me know in case you need further assistance on the same.
You are welcome Crystal. Let me know if you have any other questions on the same.
Hi Maria, use dispatcher works, thank you so much for your help.