弹窗添加
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.ViewModelBase;
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace ADP.ViewModels.Dialogs
|
||||
{
|
||||
@@ -69,6 +71,11 @@ namespace ADP.ViewModels.Dialogs
|
||||
|
||||
public DialogCloseListener RequestClose { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自动关闭定时器:自动关闭秒数大于 0 时启动,到时自动关闭弹窗(同时解除阻塞等待)
|
||||
/// </summary>
|
||||
private DispatcherTimer _autoCloseTimer;
|
||||
|
||||
public MessageBoxViewModel(IContainerProvider containerProvider):base(containerProvider)
|
||||
{
|
||||
YesCommand = new DelegateCommand(OnYes);
|
||||
@@ -93,6 +100,7 @@ namespace ADP.ViewModels.Dialogs
|
||||
|
||||
public override void OnDialogClosed()
|
||||
{
|
||||
_autoCloseTimer?.Stop();
|
||||
_eventAggregator.GetEvent<OverlayEvent>().Publish(false);
|
||||
}
|
||||
|
||||
@@ -117,6 +125,21 @@ namespace ADP.ViewModels.Dialogs
|
||||
ShowNo = parameters.GetValue<bool>("ShowNo");
|
||||
ShowOk = parameters.GetValue<bool>("ShowOk");
|
||||
ShowCancel = parameters.GetValue<bool>("ShowCancel");
|
||||
|
||||
// 自动关闭:秒数大于 0 时启动定时器,到时自动关闭(供命令库 弹窗 命令的自动关闭参数使用)
|
||||
if (parameters.TryGetValue("AutoCloseSeconds", out double autoCloseSeconds) && autoCloseSeconds > 0)
|
||||
{
|
||||
_autoCloseTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(autoCloseSeconds)
|
||||
};
|
||||
_autoCloseTimer.Tick += (s, e) =>
|
||||
{
|
||||
_autoCloseTimer.Stop();
|
||||
RequestClose.Invoke(new DialogResult(ButtonResult.OK));
|
||||
};
|
||||
_autoCloseTimer.Start();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user