Files
ShrlAlgoToolkit/Melskin/Controls/Modal/ModalWindow.xaml.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2026-01-02 17:30:41 +08:00
namespace Melskin.Controls;
2025-08-12 23:08:54 +08:00
/// <summary>
/// ModalWindow.xaml 的交互逻辑
/// </summary>
public partial class ModalWindow : Window
{
// 用于异步操作
2025-08-20 12:10:35 +08:00
/// <summary>
/// 当用户点击确定按钮时触发的异步委托。此属性允许设置一个返回布尔值的任务,用于执行自定义逻辑。
/// 如果设置了此属性,并且在用户点击确定按钮后,将调用该委托执行指定的异步操作。
/// 根据委托返回的结果决定是否关闭对话框如果返回true则对话框以成功状态关闭若返回false则保持对话框打开。
/// </summary>
2025-08-12 23:08:54 +08:00
public Func<Task<bool>>? OnOkAsync { get; set; }
2025-08-20 12:10:35 +08:00
/// <summary>
/// 代表一个模态窗口,用于显示对话框。
/// </summary>
2025-08-12 23:08:54 +08:00
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;
2025-08-20 12:10:35 +08:00
OkButton.Content = "加载中..."; // 模拟加载状态
2025-08-12 23:08:54 +08:00
2025-08-20 12:10:13 +08:00
var result = await OnOkAsync();
2025-08-12 23:08:54 +08:00
if (result)
{
this.DialogResult = true;
}
else
{
// 恢复按钮状态,停留在对话框
OkButton.IsEnabled = true;
2025-08-20 12:10:35 +08:00
OkButton.Content = "确定";
2025-08-12 23:08:54 +08:00
}
}
else
{
this.DialogResult = true;
}
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
}