AvaloniaUI / Avalonia.Controls.TreeDataGrid

A combined TreeView/DataGrid for Avalonia.
MIT License
266 stars 54 forks source link

PropertyChanged from model not handled properly #292

Open blackmole opened 4 months ago

blackmole commented 4 months ago

Hi there, I observed an issue when updating properties in the model. I hope it's not a mishandling from my side, but I think it's a bug.

Setup: I've got a model which has a property Size, which for Folders is the sum of all children sizes. I have a TreeDataGridthat has a column showing the size, AutoDragDropenabled, with Itemsonly being allowed to be dropped on Folders. The TreeDataGrid also shows another int column. Each time the ObservableCollection containing the children fires a CollectionChanged, a RaisePropertyChanged(nameof(Size)) is called.

Action: I move items around.

Expected behavior: The value in the Size column changed every time I move an item around.

Observed behavior: The value in the Size column changes every second time. (Depending on the number of int columns less often). In the following gif you can observe the behavior. Left hand side is the described behavior, right hand side as I would expect it. Only difference is the int column. Avalonia_TreeDataGrid_ValueUpdate

I tried to use a string text column with x => x.Prop.ToString(), but I get an exception: System.ArgumentException Expression of type 'System.Int32' cannot be used for return type 'System.Object'

Here's the code: https://github.com/blackmole/AvaloniaTreeDataGridValueUpdate

blackmole commented 3 months ago

This issues apparently not only appears when there are two int columns, but also for two string columns. Not sure what the exact condition is though, but when I have a table with only two strings and update the second one, it only works every second time.

My workaround: Fire the PropertyChangedevent twice. Ugly, but working.