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;
|
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;
|
}));
|
}
|
});
|
}
|
|
}
|
}
|