-
Hi, I have been trying to figure out a question of mine regarding: HackerNews/src/HackerNews/ViewModels/NewsViewModel.cs Lines 76 to 106 in aaad245 Basically, my question is: Is it OK to use ? The reason I'm asking is that And I wonder whether one can set view model properties (used in data bindings) on non-UI threads. Is it or is it not? Best regards! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good question! Short answer: Yes, in .NET MAUI it's safe to update properties in the ViewModel that are bound to the view from any thread. .NET MAUI (and Xamarin.Forms) marshall binding updates to the Main (UI) Thread, so we're totally safe setting a property in our ViewModel from any thread because MAUI's binding engine will bring the updates to the UI Thread for us. You'll want to stay aware around this, though. There has been talks amongst the engineering team to no longer marshall every binding to the UI Thread, and I've seen some instances in newer versions of .NET MAUI where it wasn't properly marshaling CollectionView updates to the UI Thread. It'd be a substantial breaking change, and I don't they'd break all of our code, but it could happen! |
Beta Was this translation helpful? Give feedback.
Good question!
Short answer: Yes, in .NET MAUI it's safe to update properties in the ViewModel that are bound to the view from any thread.
.NET MAUI (and Xamarin.Forms) marshall binding updates to the Main (UI) Thread, so we're totally safe setting a property in our ViewModel from any thread because MAUI's binding engine will bring the updates to the UI Thread for us.
You'll want to stay aware around this, though. There has been talks amongst the engineering team to no longer marshall every binding to the UI Thread, and I've seen some instances in newer versions of .NET MAUI where it wasn't properly marshaling CollectionView updates to the UI Thread. It'd be a substantial breaking change,…