protected override void OnAttached() { base.OnAttached(); Target = new DOTargetWrapper(AssociatedObject); if (Target.IsNull) { ModuleInjectionException.CannotAttach(); } if (Target.IsInitialized || !WaitForInitialization) { OnInitialized(); } else { Target.Initialized += OnTargetInitialized; } Target.DataContextChanged += OnTargetDataContextChanged; }
static void GetServices(object viewModel, bool throwIfNotSupportServices, bool checkServiceIds, out IEnumerable <IVisualStateServiceImplementation> services) { if (throwIfNotSupportServices) { Verifier.VerifyViewModelISupportServices(viewModel); } if (!(viewModel is ISupportServices)) { services = new IVisualStateServiceImplementation[] { }; return; } var serviceContainer = ((ISupportServices)viewModel).ServiceContainer; services = serviceContainer.GetServices <IVisualStateService>(true).Cast <IVisualStateServiceImplementation>(); if (checkServiceIds && services.GroupBy(x => x.Id).Where(x => x.Count() > 1).Any()) { ModuleInjectionException.VisualStateServiceName(); } }
void Init() { object vm = null; if (Factory != null) { vm = Factory(); } else if (ViewModelName != null) { vm = viewModelLocator.ResolveViewModel(ViewModelName); if (vm == null) { ModuleInjectionException.CannotResolveVM(ViewModelName); } } if (vm == null) { ModuleInjectionException.NullVM(); } if (keepViewModelAlive) { viewModel = vm; } else { viewModelRef = new WeakReference(vm); } InitParameter(); if (string.IsNullOrEmpty(ViewModelName)) { ViewModelName = viewModelLocator.GetViewModelTypeName(vm.GetType()); } InitViewType(); InitViewName(); }