App Lifecycle And Windowing
Windows App SDK desktop apps behave like desktop apps, not UWP apps. They launch, create windows, receive activation arguments, and keep running until closed or exited.
Startup Shape
public partial class App : Application
{
public static Window? MainWindow { get; private set; }
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
MainWindow = new MainWindow();
MainWindow.Activate();
}
}
Use Application.OnLaunched for basic startup. For notifications or protocol/file activation, route activation arguments explicitly and decide whether to show the window.
Windowing Model
| Need | API |
|---|---|
| XAML content window | Microsoft.UI.Xaml.Window |
| Native top-level window management | Microsoft.UI.Windowing.AppWindow |
| Interop with Win32/WPF/WinForms | HWND -> WindowId -> AppWindow |
| Presenter modes | AppWindowPresenter and presenter-specific APIs |
| Title bar customization | AppWindow.TitleBar, Window.ExtendsContentIntoTitleBar, or current TitleBar control guidance |
AppWindow From A WinUI Window
using Microsoft.UI;
using Microsoft.UI.Windowing;
using WinRT.Interop;
var hwnd = WindowNative.GetWindowHandle(App.MainWindow);
var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
var appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new Windows.Graphics.SizeInt32(1100, 760));
What Not To Use
Window.Current.Window.Dispatcher.CoreWindow.ApplicationView.GetForCurrentView().CoreApplicationViewTitleBar.
Those are UWP-era patterns and are wrong or unsupported in WinUI 3 desktop apps.
Gotcha: Track windows explicitly. Multi-window apps need a registry of open
Window/AppWindowinstances, not a global assumption thatWindow.Currentexists.