From ae7ffd003e3bed61e8f646b1e0217619a61e9914 Mon Sep 17 00:00:00 2001 From: bigworld12 Date: Fri, 2 Oct 2015 15:42:32 +0200 Subject: [PATCH 1/4] removed obsolete from IsOpen and instead made it read only , add Cancelled event , also made IsCancelled read only Note : this isn't a breaking change , only the read only properties might be breaking --- .../Dialogs/ProgressDialogController.cs | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs index 0a496dd9c9..48b2153f76 100644 --- a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs +++ b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs @@ -12,23 +12,36 @@ public class ProgressDialogController private ProgressDialog WrappedDialog { get; set; } private Func CloseCallback { get; set; } - /// - /// Gets if the wrapped ProgressDialog is open. - /// - [Obsolete("Use the Closed event instead")] - public bool IsOpen { get; private set; } + /// - /// This event is raised when the associated was closed. + /// This event is raised when the associated was closed programmatically. /// public event EventHandler Closed; + + /// + /// This event is raised when the associated was cancelled by the user. + /// + public event EventHandler Cancelled; + + /// + /// Gets if the Cancel button has been pressed. + /// + public bool IsCancelled {get{ return m_iscanceled;}} + private bool m_iscanceled; + + /// + /// Gets if the wrapped ProgressDialog is open. + /// + public bool IsOpen { get { return m_isopen; } } + private bool m_isopen; internal ProgressDialogController(ProgressDialog dialog, Func closeCallBack) { WrappedDialog = dialog; CloseCallback = closeCallBack; - IsOpen = dialog.IsVisible; + m_isopen = dialog.IsVisible; InvokeAction(() => { WrappedDialog.PART_NegativeButton.Click += PART_NegativeButton_Click; @@ -43,7 +56,12 @@ internal ProgressDialogController(ProgressDialog dialog, Func closeCallBac private void PART_NegativeButton_Click(object sender, RoutedEventArgs e) { Action action = () => { - IsCanceled = true; + m_iscanceled = true; + var handler = Cancelled; + if (handler != null) + { + handler(this, EventArgs.Empty); + } WrappedDialog.PART_NegativeButton.IsEnabled = false; }; @@ -121,10 +139,7 @@ public void SetTitle(string title) InvokeAction(() => WrappedDialog.Title = title); } - /// - /// Gets if the Cancel button has been pressed. - /// - public bool IsCanceled { get; private set; } + /// /// Begins an operation to close the ProgressDialog. @@ -135,7 +150,7 @@ public Task CloseAsync() Action action = () => { if (!WrappedDialog.IsVisible) { - throw new InvalidOperationException(); + throw new InvalidOperationException("Dialog isn't visible to close"); } WrappedDialog.Dispatcher.VerifyAccess(); WrappedDialog.PART_NegativeButton.Click -= PART_NegativeButton_Click; @@ -144,7 +159,7 @@ public Task CloseAsync() InvokeAction(action); return CloseCallback().ContinueWith(_ => InvokeAction(new Action(() => { - IsOpen = false; + m_isopen = false; var handler = Closed; if (handler != null) { From 7aefea31fd4dcb02ce35710bb876d76bfb675809 Mon Sep 17 00:00:00 2001 From: bigworld12 Date: Fri, 2 Oct 2015 15:45:17 +0200 Subject: [PATCH 2/4] change IsCanceled to IsCancelled --- samples/MetroDemo/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/MetroDemo/MainWindow.xaml.cs b/samples/MetroDemo/MainWindow.xaml.cs index cf2c28355c..fa5239c60f 100644 --- a/samples/MetroDemo/MainWindow.xaml.cs +++ b/samples/MetroDemo/MainWindow.xaml.cs @@ -259,7 +259,7 @@ private async void ShowProgressDialog(object sender, RoutedEventArgs e) controller.SetProgress(val); controller.SetMessage("Baking cupcake: " + i + "..."); - if (controller.IsCanceled) + if (controller.IsCancelled) break; //canceled progressdialog auto closes. i += 1.0; @@ -269,7 +269,7 @@ private async void ShowProgressDialog(object sender, RoutedEventArgs e) await controller.CloseAsync(); - if (controller.IsCanceled) + if (controller.IsCancelled) { await this.ShowMessageAsync("No cupcakes!", "You stopped baking!"); } From 9d5dcb063e9e8ac6feecec30cef5b5d607db04fb Mon Sep 17 00:00:00 2001 From: bigworld12 Date: Fri, 2 Oct 2015 16:05:17 +0200 Subject: [PATCH 3/4] brought back IsCanceled and simplified read only --- .../Controls/Dialogs/ProgressDialogController.cs | 12 +++++------- samples/MetroDemo/MainWindow.xaml.cs | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs index 48b2153f76..9f8a03d9c8 100644 --- a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs +++ b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs @@ -27,21 +27,19 @@ public class ProgressDialogController /// /// Gets if the Cancel button has been pressed. /// - public bool IsCancelled {get{ return m_iscanceled;}} - private bool m_iscanceled; + public bool IsCanceled { get; private set; } /// /// Gets if the wrapped ProgressDialog is open. /// - public bool IsOpen { get { return m_isopen; } } - private bool m_isopen; + public bool IsOpen { get; private set;} internal ProgressDialogController(ProgressDialog dialog, Func closeCallBack) { WrappedDialog = dialog; CloseCallback = closeCallBack; - m_isopen = dialog.IsVisible; + IsOpen = dialog.IsVisible; InvokeAction(() => { WrappedDialog.PART_NegativeButton.Click += PART_NegativeButton_Click; @@ -56,7 +54,7 @@ internal ProgressDialogController(ProgressDialog dialog, Func closeCallBac private void PART_NegativeButton_Click(object sender, RoutedEventArgs e) { Action action = () => { - m_iscanceled = true; + IsCanceled = true; var handler = Cancelled; if (handler != null) { @@ -159,7 +157,7 @@ public Task CloseAsync() InvokeAction(action); return CloseCallback().ContinueWith(_ => InvokeAction(new Action(() => { - m_isopen = false; + IsOpen = false; var handler = Closed; if (handler != null) { diff --git a/samples/MetroDemo/MainWindow.xaml.cs b/samples/MetroDemo/MainWindow.xaml.cs index fa5239c60f..cf2c28355c 100644 --- a/samples/MetroDemo/MainWindow.xaml.cs +++ b/samples/MetroDemo/MainWindow.xaml.cs @@ -259,7 +259,7 @@ private async void ShowProgressDialog(object sender, RoutedEventArgs e) controller.SetProgress(val); controller.SetMessage("Baking cupcake: " + i + "..."); - if (controller.IsCancelled) + if (controller.IsCanceled) break; //canceled progressdialog auto closes. i += 1.0; @@ -269,7 +269,7 @@ private async void ShowProgressDialog(object sender, RoutedEventArgs e) await controller.CloseAsync(); - if (controller.IsCancelled) + if (controller.IsCanceled) { await this.ShowMessageAsync("No cupcakes!", "You stopped baking!"); } From b7f2876042a3f05e7852cc580f0c17525da56801 Mon Sep 17 00:00:00 2001 From: bigworld12 Date: Fri, 2 Oct 2015 16:10:06 +0200 Subject: [PATCH 4/4] changed event to canceled --- MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs index 9f8a03d9c8..c81e520ade 100644 --- a/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs +++ b/MahApps.Metro/Controls/Dialogs/ProgressDialogController.cs @@ -22,7 +22,7 @@ public class ProgressDialogController /// /// This event is raised when the associated was cancelled by the user. /// - public event EventHandler Cancelled; + public event EventHandler Canceled; /// /// Gets if the Cancel button has been pressed. @@ -55,7 +55,7 @@ private void PART_NegativeButton_Click(object sender, RoutedEventArgs e) { Action action = () => { IsCanceled = true; - var handler = Cancelled; + var handler = Canceled; if (handler != null) { handler(this, EventArgs.Empty);