/// <summary> /// Constuctor. /// </summary> /// <param name="viewModelStore">The store this view model belongs to.</param> /// <param name="bCallIntialize">True if the Initialize method should be called.</param> protected BaseMainViewModel(ViewModelStore viewModelStore, bool bCallIntialize) : base(viewModelStore, false) { this.languagesViewModel = new LanguagesViewModel(this.ViewModelStore); this.availableModelModelContextViewModels = new List <ModelContextViewModel>(); this.allModels = new ObservableCollection <BaseDockingViewModel>(); this.allModelsRO = new ReadOnlyObservableCollection <BaseDockingViewModel>(allModels); this.unknownOpenedModels = new List <BaseDockingViewModel>(); this.validateAllCommand = new DelegateCommand(ValidateAllCommandExecuted); this.navigateBackwardCommand = new DelegateCommand(NavigateBackwardCommandExecuted, NavigateBackwardCommandCanExecute, true); this.navigateForwardCommand = new DelegateCommand(NavigateForwardCommandExecuted, NavigateForwardCommandCanExecute, true); this.ModelData.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ModelData_PropertyChanged); this.ModelData.BeforeModelContextChanged += new EventHandler(ModelData_BeforeModelContextChanged); this.ModelData.AfterModelContextChanged += new EventHandler(ModelData_AfterModelContextChanged); if (this.activeViewModel == null) { this.activeViewModel = new NullDockingViewModel(this.ViewModelStore); } this.PreInitialize(); if (bCallIntialize) { this.Initialize(); } }
/// <summary> /// Adds a view model as a child model of this view model. /// </summary> /// <param name="viewModel">View model to add to the children collection.</param> public virtual void AddViewModel(BaseDockingViewModel viewModel) { if (this.allModels.Contains(viewModel)) { return; } // create contextual ribbon bars if (this.Ribbon != null) { if (!viewModel.IsRibbonMenuInitialized && viewModel.IsInitialized) { viewModel.CreateRibbonMenu(this.Ribbon); } } this.allModels.Add(viewModel); }
/// <summary> /// This method is called from the SwitchContexts method before a switch occurs. /// </summary> /// <param name="newContextVM">New model context vm.</param> /// <param name="oldContextVM">Old model context vm.</param> protected virtual void BeforeSwitchContexts(ModelContextViewModel newContextVM, ModelContextViewModel oldContextVM) { if (oldContextVM != null) { foreach (BaseDiagramSurfaceViewModel vm in oldContextVM.AdditionalDiagramSurfaceModels) { if (vm.IsDockingPaneVisible) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } foreach (BaseDiagramSurfaceViewModel vm in oldContextVM.PluginDiagramSurfaceModels) { if (vm.IsDockingPaneVisible) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } for (int i = unknownOpenedModels.Count - 1; i >= 0; i--) { BaseDockingViewModel vm = unknownOpenedModels[i]; if (!vm.IsDisposed) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm, true)); } } } // close all view models that do not belong to the new context foreach (BaseDockingViewModel vm in this.AllViewModels) { if (vm is BaseDiagramSurfaceViewModel) { if ((vm as BaseDiagramSurfaceViewModel).ModelContextName != newContextVM.ModelContext.Name && !String.IsNullOrEmpty((vm as BaseDiagramSurfaceViewModel).ModelContextName)) { this.EventManager.GetEvent <CloseViewModelRequestEvent>().Publish(new CloseViewModelRequestEventArgs(vm)); } } } }
private void SetViewModel(ModelToolWindowPane pane, BaseDockingViewModel vm) { if( vm != null ) if (!vm.IsDisposed) { pane.Content.DataContext = vm; return; } pane.Content.DataContext = null; }