New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TreeDataGrid does not update when model properties change #128
Comments
For anyone looking for a workaround - some reflection magic on private methods does allow to refresh the cells - namely calling var rows = (HierarchicalRows<Entry>)EntriesTree.GetType()
.GetMethod("GetOrCreateRows", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(EntriesTree, null);
var evt = (NotifyCollectionChangedEventHandler)rows.GetType().GetField("CollectionChanged",
BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(rows);
if (evt != null) {
foreach (var handler in evt.GetInvocationList()) {
handler.Method.Invoke(handler.Target,
new object[]
{ rows, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset) });
}
} |
Any update on this one? This makes the grid unusable when relying on INotifyPropertyChanged for the data. |
So, I went on and went to debug the missing IPropertyChanged subscription. However, this issue is already fixed in the latest master branch for v11 by commit 58394ad "Implement cell editing for text cells." When adding the following code to the sample project on v11 to the Country model's constructor, we can observe the desired effect. I also made the model a ReactiveObject for convenience. The columns refresh as expected. Now just to wait until v11 :) Task.Run(async () =>
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(1));
Dispatcher.UIThread.Post(() =>
{
Name += "1";
this.RaisePropertyChanged(nameof(Name));
});
}
}); |
EDIT: Was my fault. Works as intended. |
This problem still happens for me with a TextColumn; my workaround was to use a TemplatedColumn... |
Describe the bug
Given an underlying model that implements
INotifyPropertyChanged
, theTreeDataGrid
doesn't update when the model is updated.To Reproduce
**For convenience, I've create a repo ready to test the issue:
https://github.com/SuperJMN-Tutorials/TreeDataGrid-Out-Of-Sync
If you want to do it yourself:
Expected behavior
After 2 seconds, the data in the DataGrid should display "How are you?". However, it shows the initial text "Hello".
NOTES
Interestingly enough, the TreeDataGrid starts to behave correctly when you click the column header. It seems that sorting a column makes it update.
Desktop (please complete the following information):
Additional context
Avalonia 0.10.18.
The text was updated successfully, but these errors were encountered: