From db68a9741e2d66030bfd97d836aeae94a8cfd1f9 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Sat, 16 Feb 2019 20:06:34 +0000 Subject: [PATCH] The multi page view can now deal with multi page view models that change the active page from a different thread (as it should be, in WPF all bound property change notifications are allowed to come from any thread) git-svn-id: file:///srv/devel/repo-conversion/nuwi@56 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/ViewModels/ThreadedViewModel.Test.cs | 4 +++- Source/Views/MultiPageViewForm.cs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Source/ViewModels/ThreadedViewModel.Test.cs b/Source/ViewModels/ThreadedViewModel.Test.cs index 0431150..34b9a03 100644 --- a/Source/ViewModels/ThreadedViewModel.Test.cs +++ b/Source/ViewModels/ThreadedViewModel.Test.cs @@ -152,7 +152,9 @@ namespace Nuclex.Windows.Forms.ViewModels { /// Runs a background process that causes the specified error /// Error that will be caused in the background process public void CauseErrorInBackgroundThread(Exception error) { - RunInBackground(() => throw error); + RunInBackground( + delegate() { throw error; } + ); } /// diff --git a/Source/Views/MultiPageViewForm.cs b/Source/Views/MultiPageViewForm.cs index 30e0064..a0ebf1f 100644 --- a/Source/Views/MultiPageViewForm.cs +++ b/Source/Views/MultiPageViewForm.cs @@ -130,7 +130,7 @@ namespace Nuclex.Windows.Forms.Views { Control control = Controls[index]; // Only check container controls - if((control is ContainerControl) || (control is Panel)) { + if((control is ContainerControl) || (control is Panel)) { if(firstContainer == null) { firstContainer = control; } @@ -194,7 +194,14 @@ namespace Nuclex.Windows.Forms.Views { if(arguments.AreAffecting(nameof(MultiPageViewModel.ActivePage))) { var viewModelAsMultiPageviewModel = DataContext as IMultiPageViewModel; if(viewModelAsMultiPageviewModel != null) { - activatePageView(viewModelAsMultiPageviewModel.GetActivePageViewModel()); + if(InvokeRequired) { + Invoke( + new Action(activatePageView), + viewModelAsMultiPageviewModel.GetActivePageViewModel() + ); + } else { + activatePageView(viewModelAsMultiPageviewModel.GetActivePageViewModel()); + } } } } @@ -210,7 +217,7 @@ namespace Nuclex.Windows.Forms.Views { var activePageViewAsView = this.activePageView as IView; if(activePageViewAsView == null) { return null; - } else { + } else { return activePageViewAsView.DataContext; } } @@ -257,7 +264,7 @@ namespace Nuclex.Windows.Forms.Views { disableActivePageView(); } else { Control pageViewContainer = getPageViewContainer(); - using(new RedrawLockScope(pageViewContainer)) { + using(new RedrawLockScope(pageViewContainer)) { disableActivePageView(); this.activePageView = getOrCreatePageView(pageViewModel);