Avalonia.Controls.TreeDataGrid icon indicating copy to clipboard operation
Avalonia.Controls.TreeDataGrid copied to clipboard

HasChildren is only evaluated once

Open SuperJMN opened this issue 3 years ago • 1 comments

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:

  1. Inside a ViewModel's constructor, create a TreeDataGrid with a root node and let its children be inside an ObservableCollection.
  2. Create a Source of type HierarchicalTreeDataGridSource.
  3. Create a HierarchicalExpanderColumn where the hasChildSelector is set to node.Children.Any(). Put a breakpoint inside this lambda expression.
  4. Don't add any children in the root node.
  5. 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.

SuperJMN avatar Oct 05 '22 10:10 SuperJMN

up! would be much appreciated to look into possible ways of solving this

dmkrupin avatar Sep 06 '24 14:09 dmkrupin