The below code is very simplified. I'm trying to abstract a dispatcher context so my view models can synchronize events that can only be raised on the GUI thread.
There's a circular reference in this pattern. Is there any other way to create a DispatcherObject
? Am I doing it wrong?
I've read other questions like this, but the answers all seem to involve a reference to the DispatcherObject
in the ViewModel
. Is this an acceptable place for a circular reference?
class ViewModel {
public DispatcherObject Dispatcher { get; set; }
}
class ModelView : UserControl {
ModelView() {
InitializeComponent();
DataContext = new ViewModel { Dispatcher = this };
}
}