mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-08-19 05:03:25 +08:00
feat.PLONDS系统开发
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Platform.Storage;
|
||||
using LanDesktopPLONDS.Installer.ViewModels;
|
||||
|
||||
@@ -22,6 +24,80 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Task 5: 安装进行中阻止关闭窗口,弹出中文确认对话框。
|
||||
/// </summary>
|
||||
protected override async void OnClosing(WindowClosingEventArgs e)
|
||||
{
|
||||
if (DataContext is not MainWindowViewModel { IsInstalling: true })
|
||||
{
|
||||
base.OnClosing(e);
|
||||
return;
|
||||
}
|
||||
|
||||
e.Cancel = true;
|
||||
var confirmed = await ShowCloseConfirmDialogAsync();
|
||||
if (confirmed)
|
||||
{
|
||||
if (DataContext is MainWindowViewModel vm)
|
||||
{
|
||||
vm.CancelInstallCommand.Execute(null);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> ShowCloseConfirmDialogAsync()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
var yesButton = new Button { Content = "确定退出", MinWidth = 100 };
|
||||
yesButton.Classes.Add("primary-command");
|
||||
yesButton.Click += (_, _) => tcs.TrySetResult(true);
|
||||
|
||||
var noButton = new Button { Content = "继续安装", MinWidth = 100 };
|
||||
noButton.Classes.Add("secondary-command");
|
||||
noButton.Click += (_, _) => tcs.TrySetResult(false);
|
||||
|
||||
var buttonPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
Spacing = 8,
|
||||
Margin = new Thickness(0, 16, 0, 0),
|
||||
};
|
||||
buttonPanel.Children.Add(yesButton);
|
||||
buttonPanel.Children.Add(noButton);
|
||||
|
||||
DockPanel.SetDock(buttonPanel, Dock.Bottom);
|
||||
|
||||
var panel = new DockPanel { Margin = new Thickness(24) };
|
||||
panel.Children.Add(buttonPanel);
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = "安装正在进行,确定要退出吗?",
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FontSize = 15,
|
||||
});
|
||||
|
||||
var dialog = new Window
|
||||
{
|
||||
Title = "确认退出",
|
||||
Width = 400,
|
||||
Height = 180,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
CanResize = false,
|
||||
WindowDecorations = WindowDecorations.BorderOnly,
|
||||
Content = panel,
|
||||
};
|
||||
|
||||
dialog.Closed += (_, _) => tcs.TrySetResult(false);
|
||||
|
||||
_ = dialog.ShowDialog(this);
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
||||
private async Task<string?> BrowseForFolderAsync(string currentPath)
|
||||
{
|
||||
IStorageFolder? startFolder = null;
|
||||
|
||||
Reference in New Issue
Block a user