-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataContext is set too early when using MEF #19
Comments
Explanation: Solutions:
public abstract class ViewModel2<TView> : ViewModelCore<TView> where TView : IView
{
protected ViewModel2(TView view) : base(view, false)
{
if (SynchronizationContext.Current is DispatcherSynchronizationContext)
{
Dispatcher.CurrentDispatcher.BeginInvoke((Action)delegate
{
ViewCore.DataContext = this;
});
}
else
{
view.DataContext = this;
}
}
}
I use the second approach for Xamarin and other non-WPF applications. |
We have migrated an WPF application from an old WPFApplicationFramework version to System.WAF.
Our application uses MEF and a plugin class that inherits from ViewModel. The plugins have an additional Initialize method. So far the DataContext was set after this method. (Dispatcher.BeginInvoke in ViewModel)
Since System.WAF 4.0.0-alpha3 that behavior changed. The DataContext is already set after the MEF import and before our Initialize method.
This leads to the fact that bindings are already executed on a plugin that is not initialized for us. Within the application there are e.g. also DataContextChanged events which are now executed too early.
Is it possible to prevent the setting of the DataContext in the OnImportsSatisfied or to get more control over it?
Thanks in advance :-)
The text was updated successfully, but these errors were encountered: