You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
748 B
C#
32 lines
748 B
C#
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
|
|
namespace Sln.Wcs.UI.Views.Base;
|
|
|
|
public partial class ConfirmDialog : Window
|
|
{
|
|
private TaskCompletionSource<bool>? _tcs;
|
|
|
|
public ConfirmDialog()
|
|
{
|
|
InitializeComponent();
|
|
CancelBtn.Click += (_, _) => CloseWith(false);
|
|
ConfirmBtn.Click += (_, _) => CloseWith(true);
|
|
}
|
|
|
|
public Task<bool> ShowDialog(string message, Window owner, string title = "确认操作")
|
|
{
|
|
TitleText.Text = title;
|
|
MessageText.Text = message;
|
|
_tcs = new TaskCompletionSource<bool>();
|
|
ShowDialog(owner);
|
|
return _tcs.Task;
|
|
}
|
|
|
|
private void CloseWith(bool result)
|
|
{
|
|
_tcs?.TrySetResult(result);
|
|
Close();
|
|
}
|
|
}
|