alielie
2026-04-16 1afe548ac40cc7f975917ef9bf2e156595cf81f3
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
using HMI.Core.Util;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
 
namespace HMI.UI
{
    /// <summary>
    /// MaskControl.xaml 的交互逻辑
    /// </summary>
    public partial class MaskControl : UserControl
    {
        public static MaskControl Instance;
 
        public static MaskControl GetInstance()
        {
            if (Instance == null)
            {
                Instance = new MaskControl();
            }
            return Instance;
        }
 
        public MaskControl()
        {
            InitializeComponent();
        }
 
        private void pausePanel_Loaded(object sender, RoutedEventArgs e)
        {
            var can = pausePanel;
            var modal = visualModal;
            Canvas.SetLeft(modal, (pausePanel.ActualWidth - visualModal.ActualWidth) / 2);
            Canvas.SetTop(modal, (pausePanel.ActualHeight - visualModal.ActualHeight) / 2.5);
        }
 
        public void ShowMask(UserControl control, Action action, Action<Exception> reject = null, string title = null, string content = null)
        {
            this.titleLabel.Content = title ?? LangUtil.Get("App.PleaseWait");
            this.contentLabel.Text = content;
            pausePanel.Visibility = Visibility.Visible;
            Task.Run(() =>
            {
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    if (reject != null) reject(ex);
                }
                finally
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        pausePanel.Visibility = Visibility.Collapsed;
                    }));
                }
            });
        }
 
    }
}