updated the closing logic of the dialog
This commit is contained in:
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;
|
||||
#endif
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControlDemo.Data;
|
||||
|
||||
namespace HandyControlDemo.ViewModel.Basic
|
||||
{
|
||||
public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable<string>
|
||||
{
|
||||
public Action<string> 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<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
|
||||
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<TextDialogWithTimer>().GetResultAsync<string>();
|
||||
Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -68,7 +69,7 @@ namespace HandyControlDemo.ViewModel
|
||||
}
|
||||
else
|
||||
{
|
||||
await Dialog.Show<TextDialogWithTimer>().GetResultAsync<string>();
|
||||
await Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class Dialog : ContentControl
|
||||
{
|
||||
private string _token;
|
||||
|
||||
private Adorner _container;
|
||||
|
||||
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
|
||||
{
|
||||
_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)
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace HandyControl.Tools.Extension
|
||||
{
|
||||
T Result { get; set; }
|
||||
|
||||
Action<string> CloseAction { get; set; }
|
||||
Action CloseAction { get; set; }
|
||||
}
|
||||
|
||||
public static class DialogExtension
|
||||
|
||||
Reference in new issue
Block a user