Added properties to access the active page view and page view model

git-svn-id: file:///srv/devel/repo-conversion/nuwi@55 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2019-02-13 22:23:28 +00:00
parent b69488f9a6
commit e16af9dee9

View File

@ -66,7 +66,7 @@ namespace Nuclex.Windows.Forms.Views {
/// <param name="cachePageViews">Whether page views should be kept alive and reused</param>
public MultiPageViewForm(IWindowManager windowManager, bool cachePageViews = false) {
this.windowManager = windowManager;
this.createViewMethod = typeof(IWindowManager).GetMethod("CreateView");
this.createViewMethod = typeof(IWindowManager).GetMethod(nameof(IWindowManager.CreateView));
if(cachePageViews) {
this.cachedViews = new Dictionary<Type, Control>();
@ -191,8 +191,7 @@ namespace Nuclex.Windows.Forms.Views {
) {
base.OnViewModelPropertyChanged(sender, arguments);
MultiPageViewModel<bool> anyMultiPageViewModel;
if(arguments.AreAffecting(nameof(anyMultiPageViewModel.ActivePage))) {
if(arguments.AreAffecting(nameof(MultiPageViewModel<object>.ActivePage))) {
var viewModelAsMultiPageviewModel = DataContext as IMultiPageViewModel;
if(viewModelAsMultiPageviewModel != null) {
activatePageView(viewModelAsMultiPageviewModel.GetActivePageViewModel());
@ -200,6 +199,23 @@ namespace Nuclex.Windows.Forms.Views {
}
}
/// <summary>Currently active page view control</summary>
protected Control ActivePageView {
get { return this.activePageView; }
}
/// <summary>The view model running the currently active page</summary>
protected object ActivePageViewModel {
get {
var activePageViewAsView = this.activePageView as IView;
if(activePageViewAsView == null) {
return null;
} else {
return activePageViewAsView.DataContext;
}
}
}
/// <summary>Activates the page view for the specified page view model</summary>
/// <param name="pageViewModel">
/// Page view model for which the page view will be activated