如何为面向 Windows 的 MAUI Blazor 应用程序设置窗口标题?
在 Platforms -> Windows 下的 App.xaml.cs 中,可以通过一些反射用法来检索 AppWindow。 然后可以在 appwindow 实例上设置 Title 属性。
In App.xaml.cs under Platforms -> Windows, the AppWindow can be retreived with some reflection usage. The Title property can then be set on the appwindow instance.
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using WinRT.Interop;
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);
var currentWindow = Application.Windows[0].Handler?.PlatformView;
IntPtr _windowHandle = WindowNative.GetWindowHandle(currentWindow);
var windowId = Win32Interop.GetWindowIdFromWindow(_windowHandle);
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.Title = "Title!";
}引用来源
https://stackoverflow.com/questions/70258689/how-to-set-window-title-for-a-maui-blazor-app-targeting-windows
赞 (0)
