You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Understand which Windows notification API to use for your app type—AppNotificationManager (Windows App SDK) vs ToastNotificationManager (WinRT/UWP)—and choose the right delivery method.
Windows provides several notification APIs across different SDK generations. If you're searching online for how to send a notification and finding conflicting examples, this page will help you pick the right API for your app.
13
+
14
+
## Which API should I use?
15
+
16
+
The answer depends on which SDK your app targets:
17
+
18
+
| App type | Recommended API | Namespace |
19
+
|---|---|---|
20
+
| WinUI 3 / Windows App SDK (new apps) |`AppNotificationManager`|`Microsoft.Windows.AppNotifications`|
21
+
| WPF, WinForms, or unpackaged Win32 |`AppNotificationManager` via NuGet |`Microsoft.Windows.AppNotifications`|
22
+
| UWP (existing apps, no migration planned) |`ToastNotificationManager`|`Windows.UI.Notifications`|
23
+
24
+
> [!IMPORTANT]
25
+
> Most Stack Overflow answers and older tutorials use `ToastNotificationManager` from the `Windows.UI.Notifications` namespace. This is the **UWP WinRT API**. It works in UWP apps and may work in some desktop scenarios, but it is not the recommended path for new Windows App SDK apps. Use `AppNotificationManager` for new development.
Copy file name to clipboardExpand all lines: hub/apps/get-started/start-here.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,9 @@ In the Visual Studio Installer, select the following workloads on the **Workload
58
58
59
59
***For C++ app development**, select the **C++ WinUI app development tools** under the **WinUI application development** node in the **Installation details** pane (This will also select any additional required components.)
60
60
61
+
> [!TIP]
62
+
> If you don't see WinUI templates after installing Visual Studio, open the Visual Studio Installer, select **Modify**, and confirm the **WinUI application development** workload is checked. Restart Visual Studio after modifying the installation.
63
+
61
64
---
62
65
63
66
## Create and launch your first WinUI app
@@ -66,6 +69,9 @@ In the Visual Studio Installer, select the following workloads on the **Workload
66
69
67
70
2. Search for **WinUI**, select the **WinUI Blank App (Packaged)** C# project template, and select **Next**.
68
71
72
+
> [!NOTE]
73
+
> The **Packaged** template is recommended for new apps. A packaged app (using MSIX) gives your users a clean install and uninstall experience, and enables Windows features like notifications, background tasks, and the Microsoft Store. You can learn more about the packaged vs. unpackaged choice in [Windows apps: packaging, deployment, and process](intro-pack-dep-proc.md).
Copy file name to clipboardExpand all lines: hub/apps/get-started/windows-developer-faq.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,18 @@ Topics covered include:
103
103
104
104
</details>
105
105
106
+
<details><summary>I get an "Unable to load DLL 'Microsoft.ui.xaml.dll'" error when running my app. How do I fix it?</summary>
107
+
108
+
> This error usually occurs in **unpackaged** app scenarios where the Windows App SDK runtime hasn't been installed on the machine. Try the following:
109
+
>
110
+
> - If you're running a **packaged** app (the recommended default), ensure you're launching via Visual Studio with the **MsixPackage** launch profile selected (not the plain executable profile). The MSIX packaging step installs the required runtime components.
111
+
> - If you're running an **unpackaged** app, you must install the [Windows App SDK runtime](../windows-app-sdk/downloads.md) separately before running the app outside of Visual Studio.
112
+
> - If the error occurs during development, open your `.csproj` and confirm that your packaging configuration matches your deployment model: for **packaged** apps, omit the `<WindowsPackageType>` property (or leave it at its default) and build/run the MSIX package; for **unpackaged** apps, set `<WindowsPackageType>None</WindowsPackageType>` and ensure you've called `Bootstrap.Initialize()` at startup.
113
+
>
114
+
> See [Deploy apps that use the Windows App SDK](../package-and-deploy/deploy-overview.md) for more details on deployment requirements.
115
+
116
+
</details>
117
+
106
118
<details><summary>What is the difference between WinUI and WinUI for UWP?</summary>
107
119
108
120
> **WinUI** (previously referred to as WinUI 3) is the latest native UI framework for Windows app development. It provides a modern and flexible UI framework for creating visually appealing and interactive Windows apps. WinUI is part of the Windows App SDK and works best with the latest versions of Windows.
# Use GitHub Copilot to create WinUI 3 / Windows App SDK apps in Visual Studio
13
13
14
-
In this how-to, we'll demonstrate how [GitHub Copilot](https://github.com/features/copilot) can be used to build WinUI / Windows App SDK desktop apps in Visual Studio. This guide builds upon *[What is GitHub Copilot Completions for Visual Studio?](/visualstudio/ide/visual-studio-github-copilot-extension)*, offering tailored tips and best practices for Copilot-assisted WinUI app development.
14
+
In this how-to, we'll demonstrate how [GitHub Copilot](https://github.com/features/copilot) can be used to build WinUI / Windows App SDK desktop apps in Visual Studio. This guide builds upon *[GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-extension)*, offering tailored tips and best practices for Copilot-assisted WinUI app development.
15
15
16
16
:::image type="content" source="images/github-copilot-winui-vs/github-copilot-extension-example.gif" alt-text="Animated screenshot that shows the code completion capabilities of the GitHub Copilot in Visual Studio.":::
17
17
18
18
## Prerequisites
19
19
20
-
- Visual Studio 2022 (v17.10+) with the **WinUI application development** workload applied (see [Get started with WinUI](../get-started/start-here.md) for additional configuration details). GitHub Copilot is included in Visual Studio 2022 v17.10 and later by default.
21
-
-An active subscription to [GitHub Copilot](https://github.com/features/copilot/plans) associated with the GitHub account that you sign in to Visual Studio with.
20
+
- Visual Studio 2022 (v17.10 or later) or Visual Studio 2026, with the **WinUI application development** workload applied (see [Set up your environment and create your first WinUI project](../get-started/start-here.md) for setup details). GitHub Copilot is included in Visual Studio 2022 v17.10 and later by default.
21
+
-A GitHub account with access to [GitHub Copilot](https://github.com/features/copilot/plans). GitHub Copilot is available for free for individual developers; paid plans are also available. Sign in to Visual Studio with the same GitHub account.
22
22
- Familiarity with C#, WinUI, and Windows App SDK.
23
23
24
24
## Use GitHub Copilot
@@ -34,46 +34,115 @@ GitHub Copilot in Visual Studio provides real-time code suggestions and completi
34
34
> [!TIP]
35
35
> If you don't see the GitHub Copilot suggestions, you can enable different aspects of the feature in Visual Studio's options under `Tools` -> `Options` -> `GitHub` -> `Copilot`.
36
36
37
-
### Ask Copilot for suggestions
37
+
### Use Copilot Chat for WinUI questions
38
38
39
-
Right-click in the code editor and select `Ask Copilot`. A prompt window will open where you can chat inline with Copilot to get a list of suggestions based on the current cursor position and your prompt:
39
+
The **Copilot Chat** panel (View > GitHub Copilot Chat) is the most flexible way to get WinUI-specific help. Unlike inline completions, Chat lets you ask multi-step questions, reference specific files, and get explanations with full context.
40
40
41
-
:::image type="content" source="images/github-copilot-winui-vs/2-generate-multiple-suggestions.png" alt-text="Screenshot that shows the inline prompting capabilities of GitHub Copilot.":::
41
+
Open the Chat panel and try prompts like:
42
+
43
+
-*"Using WinUI 3 and Windows App SDK, add a NavigationView with three pages to my MainWindow"*
44
+
-*"Explain how XamlRoot works in WinUI 3 and show me how to set it on a ContentDialog"*
45
+
-*"Convert this event handler to use DispatcherQueue instead of CoreDispatcher"*
46
+
47
+
To reference a specific file in Chat, type `#` and select the file from the picker. This is particularly useful when you want Copilot to generate C# code that matches your existing XAML:
48
+
49
+
```
50
+
#MainWindow.xaml Add click handlers in code-behind for all the buttons in this file
51
+
```
52
+
53
+
> [!TIP]
54
+
> Always include **WinUI 3** and **Windows App SDK** in your Chat prompts. Without this context, Copilot may suggest UWP patterns (such as `Window.Current` or `CoreDispatcher`) that don't work in WinUI 3. See [WinUI 3 patterns to watch for](#winui-3-patterns-to-watch-for) below.
55
+
56
+
### Ask Copilot for inline suggestions
57
+
58
+
Right-click in the code editor and select **Chat** to open an inline chat window at your cursor position. Type your question and press **Enter**:
59
+
60
+
:::image type="content" source="images/github-copilot-winui-vs/2-generate-multiple-suggestions.png" alt-text="Screenshot that shows the inline chat capabilities of GitHub Copilot.":::
61
+
62
+
> [!TIP]
63
+
> You can promote an inline chat thread to the full Chat panel at any time by selecting **Copilot Actions** > **Add to Chat**. This preserves the conversation context so you can continue in the panel.
42
64
43
65
### Prompt Copilot with plain-language comments
44
66
45
67
Although Copilot is used primarily for code completion, you can also use natural language comments to guide Copilot in generating specific code snippets. For example, you can use comments to request a specific feature or functionality:
46
68
47
69
:::image type="content" source="images/github-copilot-winui-vs/3-prompt-copilot-with-inline-comment.png" alt-text="Screenshot that shows the code completion capabilities of GitHub Copilot (prompting).":::
48
70
49
-
### Use temporary comments to add code from other files to Copilot's context
71
+
### Use Copilot Chat to add context from other files
50
72
51
-
If you're working on a code-behind file and want Copilot to incorporate context from the associated XAML file, you can use temporary comments to include this additional code within Copilot's context. Here's an example of how you can specify the XAML code first, and then have Copilot generate the corresponding C# code:
73
+
If you're working on a code-behind file and want Copilot to incorporate context from the associated XAML file, reference it directly in the Chat panel using `#`:
74
+
75
+
```
76
+
#MainPage.xaml Generate the C# event handlers for all interactive controls in this file
77
+
```
78
+
79
+
Alternatively, for inline completions you can use temporary comments to paste the relevant XAML into the code-behind file. Copilot will use this as context when generating C# code, and you can delete the comments afterward:
52
80
53
81
:::image type="content" source="images/github-copilot-winui-vs/4-add-context-temporary-comments.png" alt-text="Screenshot that shows the code completion capabilities of GitHub Copilot (context expansion).":::
54
82
55
-
### Ask Copilot to explain how something works with inline comments
83
+
### Ask Copilot to explain how something works
56
84
57
-
You can use inline comments to ask Copilot to explain how a specific piece of code works. This is similar to using the inline Ask Copilot feature or the Copilot Chat window, except your prompt is typed directly into the code editor:
85
+
The best way to ask Copilot to explain code is to select it in the editor, then right-click and choose **Copilot Actions** > **Explain**. This opens the Chat panel with your selected code already attached as context, and Copilot provides a detailed explanation.
58
86
59
-
:::image type="content" source="images/github-copilot-winui-vs/5-ask-copilot-inline-explanation.png" alt-text="Screenshot that shows the code completion capabilities of GitHub Copilot (explain).":::
87
+
You can also ask for explanations directly in the Chat panel using the `/explain` slash command:
60
88
61
-
### Use Copilot to test code standards
89
+
```
90
+
/explain What does this DispatcherQueue.TryEnqueue call do?
91
+
```
62
92
63
-
You can use Copilot to generate code that adheres to your project's coding standards, and to test any given snippet's adherence to those standards. Here's an example of how you can use inline comments to specify two conventions, and then have Copilot validate the code snippet against these conventions:
93
+
> [!TIP]
94
+
> Slash commands like `/explain`, `/fix`, and `/doc` are shortcuts in the Chat panel that tell Copilot exactly what kind of help you want. Type `/` in the Chat input to see all available commands.
64
95
65
-
:::image type="content" source="images/github-copilot-winui-vs/6-enforce-code-standards.png" alt-text="Screenshot that shows the code completion capabilities of GitHub Copilot (standards).":::
96
+
### Use Copilot to enforce code standards
97
+
98
+
The most reliable way to have Copilot follow your project's coding conventions is to add a `.github/copilot-instructions.md` file to your repository. Copilot reads this file automatically and applies the instructions to all suggestions in that repo. For example:
99
+
100
+
```markdown
101
+
# Copilot instructions
102
+
103
+
- Use DispatcherQueue.TryEnqueue for all UI thread dispatch, never CoreDispatcher
104
+
- Always set XamlRoot when showing a ContentDialog
105
+
- Use the MVVM pattern with CommunityToolkit.Mvvm ObservableObject and RelayCommand
106
+
- Target net10.0-windows10.0.19041.0 — do not use plain net10.0
107
+
```
108
+
109
+
You can also ask Copilot to review a code snippet against specific standards in the Chat panel:
110
+
111
+
```
112
+
Does this code follow the MVVM pattern correctly for a WinUI 3 app?
113
+
```
114
+
115
+
> [!TIP]
116
+
> For team-wide consistency, commit `.github/copilot-instructions.md` to source control. Every developer on the team will get the same Copilot behavior without any per-machine configuration.
117
+
118
+
## WinUI 3 patterns to watch for
119
+
120
+
Copilot is trained on a large body of Windows code that includes older UWP and WinUI 2 samples. When working in a WinUI 3 project, watch for these suggestions and use the correct WinUI 3 equivalents instead:
|`Windows.UI.Xaml.*` namespaces |`Microsoft.UI.Xaml.*`| All WinUI 3 types are in the `Microsoft.UI.Xaml` namespace |
127
+
|`MessageDialog` (Windows.UI.Popups) |`ContentDialog` with `XamlRoot` set | Set `dialog.XamlRoot = this.Content.XamlRoot` before calling `ShowAsync`|
128
+
|`FileOpenPicker` without HWND | Initialize with `WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd)`| WinUI 3 pickers require an HWND; use `WinRT.Interop` to get it |
129
+
|`net8.0` or `net10.0` TFM |`net10.0-windows10.0.19041.0`| The unqualified TFM excludes Windows Runtime APIs |
130
+
131
+
> [!TIP]
132
+
> If Copilot generates a pattern from this list, paste it into the Chat panel and ask: *"Is this correct for WinUI 3 with Windows App SDK, or is this a UWP pattern?"* Copilot will usually identify and correct the issue when asked directly.
66
133
67
134
## Recap
68
135
69
136
In this how-to, we demonstrated how to use GitHub Copilot in Visual Studio to assist you with WinUI / Windows App SDK desktop app development. We covered how to:
70
137
71
138
- Autocomplete your code snippets.
72
-
- Generate autocomplete suggestions inline with Ask Copilot.
139
+
- Use the Copilot Chat panel for multi-step WinUI questions and file references.
140
+
- Generate inline suggestions using right-click > **Chat**.
73
141
- Prompt Copilot with plain-language comments.
74
-
- Use temporary comments to add code from other files to Copilot's context.
75
-
- Ask Copilot to explain how something works with inline comments.
76
-
- Use Copilot to test and enforce code standards.
142
+
- Use `#file` references or temporary comments to add context from other files.
143
+
- Ask Copilot to explain code using **Copilot Actions** > **Explain** or the `/explain` slash command in Chat.
144
+
- Use Copilot to enforce code standards with `.github/copilot-instructions.md` or Chat review.
145
+
- Identify and correct UWP patterns that Copilot may suggest in WinUI 3 projects.
0 commit comments