using Panuon.WPF.UI;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace HMI.UI
{
///
/// MaskWindow.xaml 的交互逻辑
///
public partial class MaskWindow : WindowX
{
private Action action;
private int delay;
public MaskWindow(Window window, Action action)
{
Owner = window;
DataContext = this;
this.action = action;
InitializeComponent();
ContentRendered += MaskWindow_ContentRendered; ;
}
private string status;
public string Status
{
get { return status; }
set { Set(ref status, value); }
}
public void Info(string message, int delay = 100)
{
Status = "Info";
label.Content = message;
this.delay = delay;
this.ShowDialog();
}
private void MaskWindow_ContentRendered(object sender, EventArgs e)
{
//Dispatcher.InvokeAsync(new Action(() =>
//{
// 暂停线程令UI完全展示
// if (delay > 0) Thread.Sleep(delay);
// action(this);
//}));
Task.Run(() =>
{
try
{
// 暂停线程令UI完全展示
if (delay > 0) Thread.Sleep(delay);
action(this);
}
finally
{
Dispatcher.Invoke(() =>
{
this.Close();
});
}
});
}
private void MaskWindow_Loaded(object sender, RoutedEventArgs e)
{
}
}
}