Skip to content
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

Exception when adding items from another thread #185

Open
daniol opened this issue Jun 7, 2024 · 0 comments
Open

Exception when adding items from another thread #185

daniol opened this issue Jun 7, 2024 · 0 comments

Comments

@daniol
Copy link

daniol commented Jun 7, 2024

Describe the bug
MAUI.DataGrid does not internally handle thread synchronization for updates to its data source. When an item is added to the ObservableCollection from a thread different than the UI thread, the DataGrid does not automatically marshal the change back to the UI thread.
Calling MainThread.BeginInvokeOnMainThread when adding a item to the ItemSource collection solves the problem.

To Reproduce
Steps to reproduce the behavior:

  1. Define a DataGrid with a ItemsSource associated to an ObservableCollection
  2. Add an Item to the ObservableCollection from another thread, for example with Task.Run(() => itemList.Add(x));
  3. A COM exception is thrown when _paginationStepper.IsEnabled is changed
    _paginationStepper.IsEnabled = value > 1;

Expected behavior
Either no exception, or explicitly state on the documentation that calling BeginInvokeOnMainThread is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant