功能完善
This commit is contained in:
47
NeuWPF/NeoUI/Controls/Modal/ModalWindow.xaml.cs
Normal file
47
NeuWPF/NeoUI/Controls/Modal/ModalWindow.xaml.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace NeumUI.Controls;
|
||||
/// <summary>
|
||||
/// ModalWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ModalWindow : Window
|
||||
{
|
||||
// 用于异步操作
|
||||
public Func<Task<bool>>? OnOkAsync { get; set; }
|
||||
|
||||
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 = "Loading..."; // 模拟 Ant Design 的加载状态
|
||||
|
||||
var result = await OnOkAsync();
|
||||
if (result)
|
||||
{
|
||||
this.DialogResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 恢复按钮状态,停留在对话框
|
||||
OkButton.IsEnabled = true;
|
||||
OkButton.Content = "OK";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.DialogResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user