To start with I'm from a WPF world where I'm used to using MVVM, however my knowledge isn't up to date with regards to the new .net API and WinUI.
I'm currently trying to create a new POC using UNO Platform (which is more or less WinUI api) and MVVM, however I'm currently stuck. The problem is that I'm firing an event in my model that the view model subscribes to. The event is running on a background thread so the UI will not get updated when the view model updates the properties from the event, due to the background thread. WPF's approach to get the UI thread isn't available.
The suggestion I found is to use DispatcherQueue.GetForCurrentThread();
in the constructor of the view model. However, I'm using microsofts IOC Microsoft.Extensions.Hosting
to register the view model, so the constructor is called on a background thread and therefor having the DispatcherQueue.GetForCurrentThread();
to get the UI thread doesn't work.
Another solution would be to store the dispatcherQueue in the App.cs, but that just doesn't seems like a great idea to access the dispatcherQueue through App.
So in short, how do I update the view models properties on the UI thread when receiving an event from the model ?