winui3-migration-guide

Maps legacy UWP APIs to WinUI 3 equivalents with before-and-after C# code snippets.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill winui3-migration-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: winui3-migration-guide
Source: https://github.com/github/awesome-copilot/tree/main/skills/winui3-migration-guide
Command: npx skills add https://github.com/github/awesome-copilot --skill winui3-migration-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating UWP applications to WinUI 3 / Windows App SDK involves dozens of breaking API changes, and AI-generated code frequently uses legacy UWP patterns that fail at runtime. This Skill provides verified API mappings and corrected code snippets so migrations and code reviews avoid the most common errors.

Core Features & Use Cases

  • API Mapping Tables: Covers namespace changes, threading (CoreDispatcher to DispatcherQueue), windowing (CoreWindow to AppWindow), dialogs, pickers, background tasks, and GetForCurrentView replacements.
  • Common Mistake Detection: Documents the top Copilot code generation errors, such as ContentDialog without XamlRoot, MessageDialog usage, and CoreDispatcher calls, with corrected WinUI 3 code.
  • Migration Checklist: A 15-step checklist covering project file updates, unit test migration to WinUI test templates, and packaged versus unpackaged configuration.
  • Use Case: When reviewing generated C# code for a WinUI 3 desktop app, use this Skill to verify that dialogs set XamlRoot, pickers are initialized with a window handle, and threading uses DispatcherQueue.

Quick Start

Review this C# UWP code and migrate it to WinUI 3 using the correct Windows App SDK APIs.

Frequently Asked Questions about winui3-migration-guide

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate a UWP app to WinUI 3?

Replace all Windows.UI.Xaml namespaces with Microsoft.UI.Xaml, swap CoreDispatcher for DispatcherQueue, replace Window.Current with a static App.MainWindow property, and update the project file to target net10.0-windows10.0.22621.0 with UseWinUI enabled. Follow the 15-step checklist to cover dialogs, pickers, and tests.

How to show a ContentDialog in WinUI 3 without errors?

Set the XamlRoot property on the ContentDialog before calling ShowAsync, typically using this.Content.XamlRoot from the parent page. Omitting XamlRoot throws an InvalidOperationException in WinUI 3 desktop apps.

What replaces CoreDispatcher in WinUI 3?

DispatcherQueue replaces CoreDispatcher in WinUI 3. Use DispatcherQueue.TryEnqueue to marshal work to the UI thread, optionally passing a DispatcherQueuePriority, and check DispatcherQueue.HasThreadAccess instead of Dispatcher.HasThreadAccess.

Why does FileOpenPicker fail in a WinUI 3 desktop app?

FileOpenPicker fails because WinUI 3 desktop apps require a window handle for picker initialization. Retrieve the HWND with WinRT.Interop.WindowNative.GetWindowHandle and pass it to WinRT.Interop.InitializeWithWindow.Initialize before calling PickSingleFileAsync.

Can UWP unit test projects test WinUI 3 code?

No, UWP unit test projects do not work with WinUI 3. Migrate to the Unit Test App (WinUI in Desktop) template and use the UITestMethod attribute for any test that instantiates Microsoft.UI.Xaml types, ensuring execution on the XAML UI thread.

What replaces GetForCurrentView APIs in WinUI 3?

GetForCurrentView patterns are unavailable in WinUI 3 desktop apps. Use AppWindow.GetFromWindowId for ApplicationView scenarios, XamlRoot.RasterizationScale or Win32 GetDpiForWindow for display information, and handle back navigation directly in NavigationView.