diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs index 947ee7bc..2406d7a3 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Basic/InteractiveDialogViewModel.cs @@ -6,13 +6,12 @@ using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.CommandWpf; #endif using HandyControl.Tools.Extension; -using HandyControlDemo.Data; namespace HandyControlDemo.ViewModel.Basic { public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable { - public Action CloseAction { get; set; } + public Action CloseAction { get; set; } private string _result; @@ -38,6 +37,6 @@ namespace HandyControlDemo.ViewModel.Basic #endif } - public RelayCommand CloseCmd => new Lazy(() => new RelayCommand(() => CloseAction?.Invoke(MessageToken.MainWindow))).Value; + public RelayCommand CloseCmd => new Lazy(() => new RelayCommand(() => CloseAction?.Invoke())).Value; } } diff --git a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs index 89bc2d92..cb149c85 100644 --- a/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs +++ b/src/Shared/HandyControlDemo_Shared/ViewModel/Controls/DialogDemoViewModel.cs @@ -9,6 +9,7 @@ using GalaSoft.MvvmLight.CommandWpf; #endif using HandyControl.Controls; using HandyControl.Tools.Extension; +using HandyControlDemo.Data; using HandyControlDemo.UserControl; using HandyControlDemo.ViewModel.Basic; using HandyControlDemo.Window; @@ -51,7 +52,7 @@ namespace HandyControlDemo.ViewModel } else { - Dialog.Show().GetResultAsync(); + Dialog.Show(MessageToken.MainWindow).GetResultAsync(); } } #else @@ -68,7 +69,7 @@ namespace HandyControlDemo.ViewModel } else { - await Dialog.Show().GetResultAsync(); + await Dialog.Show(MessageToken.MainWindow).GetResultAsync(); } } #endif diff --git a/src/Shared/HandyControl_Shared/Controls/Other/Dialog.cs b/src/Shared/HandyControl_Shared/Controls/Other/Dialog.cs index 1ec03235..d117cb7d 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/Dialog.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/Dialog.cs @@ -12,6 +12,8 @@ namespace HandyControl.Controls { public class Dialog : ContentControl { + private string _token; + private Adorner _container; private static readonly Dictionary WindowDic = new Dictionary(); @@ -99,6 +101,7 @@ namespace HandyControl.Controls { var dialog = new Dialog { + _token = token, Content = content }; @@ -139,19 +142,16 @@ namespace HandyControl.Controls return dialog; } - public void Close(string token = "") + public void Close() { - if (!string.IsNullOrEmpty(token)) - { - if (WindowDic.TryGetValue(token, out var window)) - { - Close(window); - } - } - else + if (string.IsNullOrEmpty(_token)) { Close(VisualHelper.GetActiveWindow()); } + else if (WindowDic.TryGetValue(_token, out var window)) + { + Close(window); + } } private void Close(System.Windows.Window window) diff --git a/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs b/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs index 5dca7c1e..aae15918 100644 --- a/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs +++ b/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs @@ -9,7 +9,7 @@ namespace HandyControl.Tools.Extension { T Result { get; set; } - Action CloseAction { get; set; } + Action CloseAction { get; set; } } public static class DialogExtension