v1.1.0: 修复入口使用BoardEditMenu/HeadToolBar, 16:9横版UI重做, 进度条在操作时显示, 雾启工作室
This commit is contained in:
58
Better-EN5/UI/ProgressDialog.xaml.cs
Normal file
58
Better-EN5/UI/ProgressDialog.xaml.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace BetterEN5.UI
|
||||
{
|
||||
public partial class ProgressDialog : Window
|
||||
{
|
||||
public ProgressDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
var desktop = System.Windows.SystemParameters.WorkArea;
|
||||
Left = (desktop.Width - Width) / 2;
|
||||
Top = (desktop.Height - Height) / 2;
|
||||
};
|
||||
}
|
||||
|
||||
public void UpdateStatus(string text, string detail = "")
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
StatusText.Text = text;
|
||||
if (!string.IsNullOrEmpty(detail))
|
||||
DetailText.Text = detail;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task RunWithProgress(Func<ProgressDialog, Task> action)
|
||||
{
|
||||
try
|
||||
{
|
||||
await action(this);
|
||||
UpdateStatus("完成", "");
|
||||
await Task.Delay(500);
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus($"失败: {ex.Message}", "");
|
||||
await Task.Delay(1500);
|
||||
DialogResult = false;
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
public static async Task<bool> Show(Window owner, string title, Func<ProgressDialog, Task> action)
|
||||
{
|
||||
var dialog = new ProgressDialog();
|
||||
dialog.Owner = owner;
|
||||
dialog.Title = title;
|
||||
dialog.Show();
|
||||
await dialog.RunWithProgress(action);
|
||||
return dialog.DialogResult ?? false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user