/// <summary> /// Create the ViewModel and injects any services needed /// </summary> /// <param name="viewModelContext"></param> /// <param name="containerElement"></param> public virtual void CreateViewModel(Export viewModelContext, FrameworkElement containerElement) { resolver.SetContextToExportProvider(containerElement); var vm = resolver.GetExportedValue(viewModelContext); resolver.SetContextToExportProvider(null); if (vm == null) { throw new InvalidOperationException(CannotFindViewModel); } containerElement.DataContext = vm; if (Designer.IsInDesignMode) { //if the ViewModel is an IDataContextAware ViewModel then we should call the DesignTimeInitialization var dataContextAwareVM = containerElement.DataContext as IDesignTimeAware; if (dataContextAwareVM != null) { dataContextAwareVM.DesignTimeInitialization(); } } }