弹窗添加

This commit is contained in:
2026-08-27 14:26:22 +08:00
parent 6a59552bc7
commit 47b4d3837b
3 changed files with 139 additions and 0 deletions
@@ -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
}