WinUI 3
WinUI 3 is the native UI framework for new Windows desktop apps in the Windows App SDK stack.
Minimal Mental Model
<Window
x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Padding="24">
<Button Content="Click me" />
</Grid>
</Window>
The markup looks familiar if you know XAML, but the runtime is desktop WinUI 3, not UWP XAML.
Use These Namespaces
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Windowing;
Do not use these for WinUI 3 app code:
using Windows.UI.Xaml;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
WinUI 3 Versus UWP WinUI 2
| Topic | WinUI 3 | UWP/WinUI 2 |
|---|---|---|
| App model | Desktop app through Windows App SDK | UWP app model |
| Namespace | Microsoft.UI.Xaml | Windows.UI.Xaml |
| Windowing | Window, HWND, AppWindow | CoreWindow, ApplicationView |
| Dispatcher | DispatcherQueue | CoreDispatcher |
| Dialogs | ContentDialog with XamlRoot | UWP dialog patterns |
| Lifecycle | Desktop-like | Suspend/resume UWP lifecycle |
ContentDialog Pattern
var dialog = new ContentDialog
{
Title = "Delete item?",
Content = "This cannot be undone.",
PrimaryButtonText = "Delete",
CloseButtonText = "Cancel",
XamlRoot = this.Content.XamlRoot,
};
await dialog.ShowAsync();
Gotcha: A
ContentDialogwithoutXamlRootis a classic AI-generated WinUI 3 bug.