namespace MyApp
{
public sealed partial class MainWindow : Window
{
AppWindow m_appWindow;
public MainWindow()
{
this.InitializeComponent();
m_appWindow = GetAppWindowForCurrentWindow();
}
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(myWndId);
}
private void SwitchPresenter_FullScreen(object sender, RoutedEventArgs e)
{
m_appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
}
}
}
Run Code Online (Sandbox Code Playgroud)
SwitchPresenter_FullScreen 功能有效,但如何将应用程序的默认窗口模式设置为全屏?我可以在应用程序启动时调用 SwitchPresenter_FullScreen 吗?