public void InsertPage(int index, IWizardPage page) { Argument.IsNotNull(() => page); Log.Debug("Adding page '{0}' to index '{1}'", page.GetType().GetSafeFullName(), index); page.Wizard = this; page.Number = index + 1; _pages.Insert(index, page); }
#pragma warning disable WPF0005 // Name of PropertyChangedCallback should match registered name. private void UpdatePage() #pragma warning restore WPF0005 // Name of PropertyChangedCallback should match registered name. { if (AssociatedObject is null) { return; } var wizard = Wizard; if (wizard is null) { return; } if (_lastPage != null) { if (ReferenceEquals(_lastPage, wizard.CurrentPage)) { // Nothing has really changed return; } _lastPage.ViewModel = null; _lastPage = null; } _lastPage = wizard.CurrentPage; var serviceLocator = this.GetServiceLocator(); var viewModelLocator = serviceLocator.ResolveType <IWizardPageViewModelLocator>(); var pageViewModelType = viewModelLocator.ResolveViewModel(_lastPage.GetType()); var viewLocator = serviceLocator.ResolveType <IViewLocator>(); var viewType = viewLocator.ResolveView(pageViewModelType); var typeFactory = serviceLocator.ResolveType <ITypeFactory>(); var view = typeFactory.CreateInstance(viewType) as IView; if (view is null) { return; } var viewModelFactory = serviceLocator.ResolveType <IViewModelFactory>(); var viewModel = viewModelFactory.CreateViewModel(pageViewModelType, wizard.CurrentPage, null); _lastPage.ViewModel = viewModel; view.DataContext = viewModel; AssociatedObject.SetCurrentValue(ContentControl.ContentProperty, view); }
public void RemovePage(IWizardPage page) { Argument.IsNotNull(() => page); for (int i = 0; i < _pages.Count; i++) { if (ReferenceEquals(page, _pages[i])) { Log.Debug("Removing page '{0}' at index '{1}'", page.GetType().GetSafeFullName(), i); page.Wizard = null; _pages.RemoveAt(i--); } } }
private void UpdatePage() { if (AssociatedObject == null) { return; } var wizard = Wizard; if (wizard == null) { return; } if (_lastPage != null) { _lastPage.ViewModel = null; _lastPage = null; } _lastPage = wizard.CurrentPage; var serviceLocator = this.GetServiceLocator(); var viewModelLocator = serviceLocator.ResolveType <IWizardPageViewModelLocator>(); var pageViewModelType = viewModelLocator.ResolveViewModel(_lastPage.GetType()); var viewLocator = serviceLocator.ResolveType <IViewLocator>(); var viewType = viewLocator.ResolveView(pageViewModelType); var typeFactory = serviceLocator.ResolveType <ITypeFactory>(); var view = typeFactory.CreateInstance(viewType) as IView; if (view == null) { return; } // TODO: Consider setting the data context to a model instead of manually creating a vm var viewModelFactory = serviceLocator.ResolveType <IViewModelFactory>(); var viewModel = viewModelFactory.CreateViewModel(pageViewModelType, wizard.CurrentPage, null); _lastPage.ViewModel = viewModel; view.DataContext = viewModel; AssociatedObject.Content = view; }
#pragma warning disable WPF0005 // Name of PropertyChangedCallback should match registered name. private void UpdatePage() #pragma warning restore WPF0005 // Name of PropertyChangedCallback should match registered name. { if (AssociatedObject is null) { return; } var wizard = Wizard; if (wizard is null) { return; } var lastPage = _lastPage; if (lastPage is not null) { if (ReferenceEquals(lastPage, wizard.CurrentPage)) { // Nothing has really changed return; } _scrollPositions.AddOrUpdate(lastPage, new ScrollInfo { VerticalOffset = _scrollViewer.VerticalOffset, HorizontalOffset = _scrollViewer.HorizontalOffset }); // Even though we cache views, we need to re-use the vm's since the view models will be closed when moving next //_lastPage.ViewModel = null; if (CacheViews) { _cachedViews.AddOrUpdate(lastPage, new CachedView { View = AssociatedObject.Content as IView }); } _lastPage = null; } _lastPage = wizard.CurrentPage; var dependencyResolver = this.GetDependencyResolver(); var viewModelLocator = dependencyResolver.Resolve <IWizardPageViewModelLocator>(); var pageViewModelType = viewModelLocator.ResolveViewModel(_lastPage.GetType()); var viewLocator = dependencyResolver.Resolve <IViewLocator>(); var viewType = viewLocator.ResolveView(pageViewModelType); var typeFactory = dependencyResolver.Resolve <ITypeFactory>(); IView view = null; if (_cachedViews.TryGetValue(_lastPage, out var cachedView)) { view = cachedView.View; } if (view is null) { view = typeFactory.CreateInstance(viewType) as IView; if (view is null) { return; } } // For now always recreate a vm since it could be closed (and we really don't want to mess with the lifetime of a view) //var viewModel = view.DataContext as IViewModel; IViewModel viewModel = null; if (viewModel is null) { var viewModelFactory = dependencyResolver.Resolve <IViewModelFactory>(); viewModel = viewModelFactory.CreateViewModel(pageViewModelType, wizard.CurrentPage, null); view.DataContext = viewModel; } _lastPage.ViewModel = viewModel; AssociatedObject.SetCurrentValue(ContentControl.ContentProperty, view); var verticalScrollViewerOffset = 0d; var horizontalScrollViewerOffset = 0d; if (_scrollPositions.TryGetValue(_lastPage, out var scrollInfo)) { verticalScrollViewerOffset = scrollInfo.VerticalOffset; horizontalScrollViewerOffset = scrollInfo.HorizontalOffset; } var scrollViewer = _scrollViewer; if (scrollViewer is not null && (Wizard?.RestoreScrollPositionPerPage ?? true)) { scrollViewer.ScrollToVerticalOffset(verticalScrollViewerOffset); scrollViewer.ScrollToHorizontalOffset(horizontalScrollViewerOffset); } }