using Microsoft.Maui.Controls; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Handlers; namespace Hua.Todo.Maui.Views { /// /// Windows 平台特定的 MainPage 逻辑(分部类)。 /// 该文件仅在 Windows 目标框架下参与编译,用于接入 Windows 全局键盘事件等能力。 /// public partial class MainPage { private Platforms.Windows.WindowsKeyboardHandler? _keyboardHandler; /// /// Windows 平台特定的键盘处理器设置。 /// 当前仅监听 Esc 键,用于快速最小化窗口(与桌面端交互习惯保持一致)。 /// partial void PlatformSetupKeyboardHandler() { _keyboardHandler = new Platforms.Windows.WindowsKeyboardHandler(); _keyboardHandler.EscKeyPressed += OnEscKeyPressed; _keyboardHandler.Start(); } /// /// Windows 平台特定的 Esc 键处理(最小化窗口)。 /// /// 当前窗口。 partial void PlatformOnEscKeyPressed(Window window) { var windowService = new Platforms.Windows.WindowsWindowService(); windowService.MinimizeWindow(window); } /// /// 配置 WebView 滚动条行为。 /// partial void ConfigureWebViewScrollBars() { // 使用 JavaScript 注入的方式禁用滚动条 MainWebView.EvaluateJavaScriptAsync(@" // 禁用页面垂直滚动条 document.body.style.overflowY = 'hidden'; // 禁用整个文档的滚动 document.documentElement.style.overflowY = 'hidden'; "); } partial void PlatformPrepareWebViewContainer() { if (Platforms.Windows.WebView2RuntimeDetector.IsRuntimeInstalled(out _)) { return; } _isWebViewContainerReady = false; var downloadUrl = "https://developer.microsoft.com/microsoft-edge/webview2/"; var content = new VerticalStackLayout { Padding = new Thickness(20), Spacing = 12, Children = { new Label { Text = "检测到系统未安装 WebView2 Runtime,无法加载主界面。", FontSize = 16 }, new Label { Text = "请安装 Microsoft Edge WebView2 Runtime(Evergreen),安装完成后重新打开应用。", Opacity = 0.85 }, new Button { Text = "打开下载页面", Command = new Command(async () => { await Launcher.Default.OpenAsync(downloadUrl); }) }, new Button { Text = "退出应用", Command = new Command(() => { Microsoft.Maui.Controls.Application.Current?.Quit(); }) } } }; Content = new ScrollView { Content = content }; } } }