Closed julian-baumann closed 2 months ago
Dispatcher.UiTread.Post should be used iirc. Can you try this?
One more hint, you can try DynamicData if you need async manipulations. It's shipped with ReactiveUI anyways
Both approaches don't work. Neither Dispatcher.UiTread.Post
nor using SourceList
with an ReadOnlyObservableCollection
updates the UI
[RelayCommand]
private async Task LoadPeopleAsync()
{
await Task.Delay(1000);
People = new ObservableCollection<Person>();
await Task.Delay(1000);
People.Add(new Person { FirstName = "John", LastName = "Doe" });
People.Add(new Person { FirstName = "Jane", LastName = "Doe" });
await Task.Delay(1000);
People.Add(new Person { FirstName = "Julie", LastName = "Doe" });
Dispatcher.UIThread.Invoke(() =>
{
People.Add(new Person { FirstName = "Norman", LastName = "Doe" });
});
}
Just tried it on my own and all of the above works. Note: I use a Command here to bind it to a button, but this is not required.
I see that you don't even await your Task, so maybe this is the issue. In any case, I think it is something in your code that blocks the UI: So I make it a Q&A for now.
Describe the bug
I am using the DataGrid component and Avalonia Version 11.1.3. Using a ViewModel I defined a Property
Entries
where I bind theItemsSource
to. I am calling a method using a Command, that updates this collection. When doing it in a synchronous environment everything works just fine, but as soon as I usedTask.Run
to run the logic and updated it usingDispatcher.UIThread.Invoke
, nothing happens. No exception is thrown, and no UI updates in the DataGrid.To Reproduce
Using DataGrid, Bindings and a ReactiveUI ViewModel
Expected behavior
No response
Avalonia version
11.1.3
OS
macOS
Additional context
No response