首先先建立一個 method 用來取得 AppWindow ,方便未來復用:
然後就可以設定顯示模式,這裡示範以全螢幕顯示:
AppWindowPresenterKind 列舉細項:
參考資料:
Microsoft.Learn - Windowing functionality migration#Full-screen
Microsoft.Learn - AppWindowPresenterKind Enum
Github Discussions - How can I set App title in winui3 desktop app
stack overflow - How To Set Default Window Mode to Full Screen in WinUI3?
using Microsoft.UI;
using WinRT.Interop;
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
然後就可以設定顯示模式,這裡示範以全螢幕顯示:
AppWindow appWindow = GetAppWindowForCurrentWindow();
appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
AppWindowPresenterKind 列舉細項:
- Default: 預設
- CompactOverlay: 緊湊
- FullScreen: 全螢幕
- Overlapped: 重疊
參考資料:
Microsoft.Learn - Windowing functionality migration#Full-screen
Microsoft.Learn - AppWindowPresenterKind Enum
Github Discussions - How can I set App title in winui3 desktop app
stack overflow - How To Set Default Window Mode to Full Screen in WinUI3?
留言
張貼留言
如果有任何問題、建議、想說的話或文章題目推薦,都歡迎留言或來信: a@ruyut.com