56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
namespace Melskin.Controls;
|
||
/// <summary>
|
||
/// ModalWindow.xaml 的交互逻辑
|
||
/// </summary>
|
||
public partial class ModalWindow : Window
|
||
{
|
||
// 用于异步操作
|
||
/// <summary>
|
||
/// 当用户点击确定按钮时触发的异步委托。此属性允许设置一个返回布尔值的任务,用于执行自定义逻辑。
|
||
/// 如果设置了此属性,并且在用户点击确定按钮后,将调用该委托执行指定的异步操作。
|
||
/// 根据委托返回的结果决定是否关闭对话框:如果返回true,则对话框以成功状态关闭;若返回false,则保持对话框打开。
|
||
/// </summary>
|
||
public Func<Task<bool>>? OnOkAsync { get; set; }
|
||
|
||
/// <summary>
|
||
/// 代表一个模态窗口,用于显示对话框。
|
||
/// </summary>
|
||
public ModalWindow(string title, string message)
|
||
{
|
||
InitializeComponent();
|
||
TitleTextBlock.Text = title;
|
||
MessageTextBlock.Text = message;
|
||
}
|
||
|
||
private async void OkButton_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
if (OnOkAsync != null)
|
||
{
|
||
OkButton.IsEnabled = false;
|
||
OkButton.Content = "加载中..."; // 模拟加载状态
|
||
|
||
var result = await OnOkAsync();
|
||
if (result)
|
||
{
|
||
this.DialogResult = true;
|
||
}
|
||
else
|
||
{
|
||
// 恢复按钮状态,停留在对话框
|
||
OkButton.IsEnabled = true;
|
||
OkButton.Content = "确定";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.DialogResult = true;
|
||
}
|
||
}
|
||
|
||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
this.DialogResult = false;
|
||
}
|
||
}
|
||
|