From d881eead1891a94c913b1bba4d0e945fcbf8ce08 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Tue, 1 Nov 2011 13:33:53 +0000 Subject: [PATCH] Wizard: fixed closing parent window exception when window was not shown with ShowDialog. --- .../Wizard/Implementation/Wizard.cs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs index fc0df23f..8a82194c 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Interop; namespace Microsoft.Windows.Controls { @@ -108,7 +109,7 @@ namespace Microsoft.Windows.Controls get { return (double)GetValue(ExteriorPanelMinWidthProperty); } set { SetValue(ExteriorPanelMinWidthProperty, value); } } - + public static readonly DependencyProperty FinishButtonClosesWindowProperty = DependencyProperty.Register("FinishButtonClosesWindow", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true)); public bool FinishButtonClosesWindow @@ -370,20 +371,11 @@ namespace Microsoft.Windows.Controls Window window = Window.GetWindow(this); if (window != null) { - try - { + //we can only set the DialogResult if the window was opened as modal with the ShowDialog() method. Otherwise an exception would occur + if (ComponentDispatcher.IsThreadModal) window.DialogResult = dialogResult; - } - catch (InvalidOperationException) - { - //DialogResult can be set only after Window is created and shown as dialog. - //So if the Window is not shown as a dialog then an exception would occur. Therefore - //let's just swallow the exception - } - finally - { - window.Close(); - } + + window.Close(); } }