updated the closing logic of the dialog

This commit is contained in:
NaBian committed 2019-07-06 13:54:39 +08:00
1 parent cb4f5b4907
commit c295bf91c9
4 files changed
+15 -15

No files matched your search

@@ -6,13 +6,12 @@ using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
#endif #endif
using HandyControl.Tools.Extension; using HandyControl.Tools.Extension;
using HandyControlDemo.Data;
namespace HandyControlDemo.ViewModel.Basic namespace HandyControlDemo.ViewModel.Basic
{ {
public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable<string> public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable<string>
{ {
public Action<string> CloseAction { get; set; } public Action CloseAction { get; set; }
private string _result; private string _result;
@@ -38,6 +37,6 @@ namespace HandyControlDemo.ViewModel.Basic
#endif #endif
} }
public RelayCommand CloseCmd => new Lazy<RelayCommand>(() => new RelayCommand(() => CloseAction?.Invoke(MessageToken.MainWindow))).Value; public RelayCommand CloseCmd => new Lazy<RelayCommand>(() => new RelayCommand(() => CloseAction?.Invoke())).Value;
} }
} }
@@ -9,6 +9,7 @@ using GalaSoft.MvvmLight.CommandWpf;
#endif #endif
using HandyControl.Controls; using HandyControl.Controls;
using HandyControl.Tools.Extension; using HandyControl.Tools.Extension;
using HandyControlDemo.Data;
using HandyControlDemo.UserControl; using HandyControlDemo.UserControl;
using HandyControlDemo.ViewModel.Basic; using HandyControlDemo.ViewModel.Basic;
using HandyControlDemo.Window; using HandyControlDemo.Window;
@@ -51,7 +52,7 @@ namespace HandyControlDemo.ViewModel
} }
else else
{ {
Dialog.Show<TextDialogWithTimer>().GetResultAsync<string>(); Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
} }
} }
#else #else
@@ -68,7 +69,7 @@ namespace HandyControlDemo.ViewModel
} }
else else
{ {
await Dialog.Show<TextDialogWithTimer>().GetResultAsync<string>(); await Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
} }
} }
#endif #endif
@@ -12,6 +12,8 @@ namespace HandyControl.Controls
{ {
public class Dialog : ContentControl public class Dialog : ContentControl
{ {
private string _token;
private Adorner _container; private Adorner _container;
private static readonly Dictionary<string, System.Windows.Window> WindowDic = new Dictionary<string, System.Windows.Window>(); private static readonly Dictionary<string, System.Windows.Window> WindowDic = new Dictionary<string, System.Windows.Window>();
@@ -99,6 +101,7 @@ namespace HandyControl.Controls
{ {
var dialog = new Dialog var dialog = new Dialog
{ {
_token = token,
Content = content Content = content
}; };
@@ -139,19 +142,16 @@ namespace HandyControl.Controls
return dialog; return dialog;
} }
public void Close(string token = "") public void Close()
{ {
if (!string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(_token))
{
if (WindowDic.TryGetValue(token, out var window))
{
Close(window);
}
}
else
{ {
Close(VisualHelper.GetActiveWindow()); Close(VisualHelper.GetActiveWindow());
} }
else if (WindowDic.TryGetValue(_token, out var window))
{
Close(window);
}
} }
private void Close(System.Windows.Window window) private void Close(System.Windows.Window window)
@@ -9,7 +9,7 @@ namespace HandyControl.Tools.Extension
{ {
T Result { get; set; } T Result { get; set; }
Action<string> CloseAction { get; set; } Action CloseAction { get; set; }
} }
public static class DialogExtension public static class DialogExtension