Question

I'm developing an application with Sasha Barber's Cinch Framework for MVVM in WPF. This application shows two tabs. The MainWindowViewModel started a background worker that listens for incoming socket connections. If a client connects via the socket connection to the application the application should show up another tab. I setted up everything well but when I try to add the new Worskspace to the Views collection I receive an error that this can only be done in an dispatcher thread but there is no dispatcher in the MainWindowViewModel. So here's my question: How can I add this workspace to the views collection?

Greets and thanks Knutman

No correct solution

OTHER TIPS

You could add a property with the following implementation to your VM base class.

public class ViewModelBase : ....
{
    protected Dispatcher Dispatcher
    {
        get { return Application.Current.Dispatcher; }
    }
}

Now you have a dispatcher in your VM. For more information, please have a look here. Or you simply use Application.Current.Dispatcher at the place where you're needing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top