dancepanda42
✅ WPF - how to correctly call a method in the ViewModel when an event occurs in the View?
Simple answer, a event handler has no return type. The method should look like this:
private async void MyToolWindow_LoadedAsync(object sender, RoutedEventArgs e)
But the right way with a viewmodel is the MVVM Pattern.
https://learn.microsoft.com/de-de/archive/msdn-magazine/2009/february/patterns-wpf-apps-with-the-model-view-viewmodel-design-pattern15 replies
Application called an interface that was marshalled for a different thread?
Here is another solution spezific for MAUI
https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/appmodel/main-thread?view=net-maui-7.0
31 replies
Application called an interface that was marshalled for a different thread?
Hi, you could try to get a reference of the UI thread through the SynchronisationContext class
https://learn.microsoft.com/en-us/dotnet/api/system.threading.synchronizationcontext?view=net-7.0
In the constructor store the SynchronisationContext.Current value in a Private filed. So you can call the Post mehtod in your Event handler to execute the passed method on the UI thread.
31 replies