wenxiangchao
2026-11-02 9d1660270272180cd71147d6ddd53d1382643d2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Panuon.WPF.UI;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
 
namespace HMI.UI
{
    /// <summary>
    /// MaskWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MaskWindow : WindowX
    {
 
        private Action<MaskWindow> action;
        private int delay;
        public MaskWindow(Window window, Action<MaskWindow> 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)
        {
 
        }
    }
}