Bil*_*obs 1 c# windows winui winui-3
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 吗?
不,不要SwitchPresenter_FullScreen直接打电话。此方法适用于您的 UI 控件(例如CheckBox或ToggleButton)。
只需将此行添加到您的MainWindow构造函数中即可。
public MainWindow()
{
this.InitializeComponent();
m_appWindow = GetAppWindowForCurrentWindow();
m_appWindow.SetPresenter(AppWindowPresenterKind.FullScreen); // This line
}
Run Code Online (Sandbox Code Playgroud)