diff --git a/CHANGELOG.md b/CHANGELOG.md index e8cbbeec..17eb1e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and is followi NOTE: Features with breaking changes are found on branch [releases/v8](https://github.com/FantasticFiasco/mvvm-dialogs/tree/releases/v8) and will stay there until a new major version is released. Until then the features have been published to [www.nuget.org](https://www.nuget.org/packages/MvvmDialogs/) as pre-releases to v8. +### :syringe: Changed + +- [#116](https://github.com/FantasticFiasco/mvvm-dialogs/issues/116) [BREAKING CHANGE] `IDialogService.Close` returns `false` instead of throwing an exception when failing to close a dialog. This behavior aligns with the behavior of `IDialogService.Activate`. + ### :syringe: Fixed - Specify dependency groups in nuspec for each supported framework version diff --git a/src/net/DialogService.cs b/src/net/DialogService.cs index e658a417..128cfaf2 100644 --- a/src/net/DialogService.cs +++ b/src/net/DialogService.cs @@ -162,25 +162,30 @@ public bool Activate(INotifyPropertyChanged viewModel) } /// - public void Close(INotifyPropertyChanged viewModel) + public bool Close(INotifyPropertyChanged viewModel) { if (viewModel == null) throw new ArgumentNullException(nameof(viewModel)); foreach (Window? window in Application.Current.Windows) { - if (window == null) + if (window == null || !viewModel.Equals(window.DataContext)) { continue; } - if (viewModel.Equals(window.DataContext)) + try { window.Close(); - return; + return true; + } + catch (Exception e) + { + Logger.Write($"Failed to close dialog: {e}"); + break; } } - throw new DialogNotFoundException(); + return false; } /// diff --git a/src/net/IDialogService.cs b/src/net/IDialogService.cs index b802b263..de200cf1 100644 --- a/src/net/IDialogService.cs +++ b/src/net/IDialogService.cs @@ -134,10 +134,10 @@ void Show( /// or . /// /// The view model of the dialog to close. - /// - /// No dialog is found with specified view model as data context. - /// - void Close(INotifyPropertyChanged viewModel); + /// + /// true if the was successfully closed; otherwise, false. + /// + bool Close(INotifyPropertyChanged viewModel); /// /// Displays a message box that has a message, title bar caption, button, and icon; and