Hi,
I have a XamDataTree with check boxes, with the check box mode set to auto, so the checks are propagation up/down and a node target with a CheckBoxMember path set.
I need to be able to reload the tree and have the previously check nodes still checked. So what I am doing is keeping track of the checked nodes then when I rebuild my collection of nodes I set the IsChecked property to true objects that match the previously selected.
My problem is when I bind this collection the correct nodes are checked but their parents will not show indeterminate etc.
I have included a simple example to try and show what I am doing.
Thanks
When t he tree binds we expect that the underlying data model is "correct". That means, nodes that should be marked as true are set to true, ones that are false should be marked as false, and those that are null should be marked as null.
In your data model, the IsChecked is bool, so when you check off the checkbox you can only store two states false/true. When you persist your data you can only see that the nodes are true, and save them, and the restore them.
When you set your new datasouce, the tree is not going to touch each of your nodes to redetermine your state. It could hurt performance having to delve into the entire tree to try and restored information that should already be there.
Thanks for pointing that out, I had knocked together the sample rather quickly and hadn't noticed my errors. I have updated the sample and I still have the same problem occurring. Apologies for the poor quality of the sample.
Ok so there are two things which appear wrong with the way you are looking for your nodes in this sample:
This first is that the FindNode method will exit out too early if it is not found in the first parent.
The method is written as (or similar to)
foreach
(SimpleNode node in nodes)
{
if (node.Name == name)
return node;
return FindNode(node.Children, name);
}
You should not be returning from FindNode unless it found a matching node. As written the foreach (SimpleNode in Nodes) loop would only look at the first member of any collection prior to exiting (found or unfound). The loop should look more like
foreach (SimpleNode node in nodes) { if (node.Name == name) return node; SimpleNode nodex = FindNode(node.Children, name); if (nodex != null) return nodex; }
Here the lower findNode calls have to actually return something to be seen as an exit case.
The second thing I noticed was that with your data, your deeper levels of nodes would never be found when you are looking for the name of a string. The second and third of data are the same for each parent node, so when you search for "Node 1-0" it will always find the "Node 1-0" under the "Node 0-0" and terminate.
If your IsChecked field is not persisted in a table or backing store, and you are recreating your data all the time, you would need to find a more unique way of identifing your data. Now this could just be a sample issue, but its visible.