HasChildren is only evaluated once
The hasChildrenSelector in HierarchicalExpanderColumn is only evaluated once. This means that, if the children collection is modified, the selector should be re-evaluated.
Repro
I've prepared a minimal repro HERE.
Run it and you will see how the 2 TreeDataGrids behave differently even though they're using the same tree (same nodes).
https://user-images.githubusercontent.com/3109851/194044436-a4bf23d2-e6e3-4377-a766-1e288dae417c.mp4
Please, notice that if you run the sample and click the expand button before the root has any children, it won't be expandable either!
Manual repro:
In case you want to warm up your hands, you can create your own repro with the steps below:
- Inside a ViewModel's constructor, create a TreeDataGrid with a root node and let its children be inside an
ObservableCollection. - Create a Source of type
HierarchicalTreeDataGridSource. - Create a
HierarchicalExpanderColumnwhere thehasChildSelectoris set tonode.Children.Any(). Put a breakpoint inside this lambda expression. - Don't add any children in the root node.
- Put code that will add children to the collection AFTER the TreeDataGrid is displayed on the screen. For example, a Button that will add children when clicked.
Result: If you add children after the TreeDataGrid is initialized and shown, the breakpoint won't be hit, and the root node will never be expandable (the little expander won't show)
Expected: The breakpoint should be hit and the "has children" condition should be re-evaluated.
up! would be much appreciated to look into possible ways of solving this