Skip to content

Commit 28eadf8

Browse files
Merge pull request #5766 from MicrosoftDocs/main
Auto Publish – main to live - 2025-09-02 20:11 UTC
2 parents 1aa1803 + 141f9f8 commit 28eadf8

File tree

8 files changed

+95
-54
lines changed

8 files changed

+95
-54
lines changed

hub/apps/get-started/start-here.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Now your project is using the latest WinUI features that are available, and it's
155155
## Next steps
156156

157157
> [!div class="nextstepaction"]
158-
> [Complete a tutorial to create a note app with WinUI](../tutorials/winui-notes/index.yml)
158+
> [Complete a tutorial to create a note app with WinUI](../tutorials/winui-notes/intro.md)
159159

160160
* To get an idea of what WinUI has to offer, check out the WinUI Gallery app.
161161
[!INCLUDE [winui-3-gallery](../../includes/winui-3-gallery.md)]

hub/apps/toc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ items:
1616
href: get-started/start-here.md
1717
- name: Build your first app
1818
href: tutorials/winui-notes/intro.md
19+
items:
20+
- name: 1 - Project setup
21+
href: tutorials/winui-notes/project.md
22+
- name: 2 - Note page
23+
href: tutorials/winui-notes/note.md
24+
- name: 3 - View and model
25+
href: tutorials/winui-notes/view-model.md
26+
- name: 4 - All notes
27+
href: tutorials/winui-notes/all-notes.md
28+
- name: 5 - Navigation
29+
href: tutorials/winui-notes/navigation.md
1930
- name: Samples and resources
2031
href: get-started/samples.md
2132
- name: Best practices

hub/apps/tutorials/winui-notes/includes/all-notes.md renamed to hub/apps/tutorials/winui-notes/all-notes.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: WinUI Notes 3
3-
description: WinUI Notes 3
2+
title: WinUI Notes tutorial - Step 4 - All notes
3+
description: WinUI Notes - Step 4 - Add a view and model for all notes.
44
author: jwmsft
55
ms.author: jimwalk
6-
ms.date: 03/26/2025
6+
ms.date: 09/02/2025
77
ms.topic: tutorial
88
no-loc: ["NotePage.xaml", "NotePage.xaml.cs", "Note.cs", "AllNotesPage.xaml", "AllNotes.cs", "WinUI 3 Gallery"]
99
---
10+
# Add a view and model for all notes
1011

1112
This portion of the tutorial adds a new page to the app, a view that displays all of the notes previously created.
1213

@@ -88,12 +89,12 @@ The new data model represents the data required to display multiple notes. Here,
8889

8990
The previous code declares a collection of `Note` items, named `Notes`, and uses the `LoadNotes` method to load notes from the app's local storage.
9091

91-
The `Notes` collection uses an [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1), which is a specialized collection that works well with data binding. When a control that lists multiple items, such as an [ItemsView](../../../design/controls/itemsview.md), is bound to an `ObservableCollection`, the two work together to automatically keep the list of items in sync with the collection. If an item is added to the collection, the control is automatically updated with the new item. If an item is added to the list, the collection is updated.
92+
The `Notes` collection uses an [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1), which is a specialized collection that works well with data binding. When a control that lists multiple items, such as an [ItemsView](../../design/controls/itemsview.md), is bound to an `ObservableCollection`, the two work together to automatically keep the list of items in sync with the collection. If an item is added to the collection, the control is automatically updated with the new item. If an item is added to the list, the collection is updated.
9293

93-
:::image type="icon" source="../media/doc-icon-sm.png" border="false"::: Learn more in the docs:
94+
:::image type="icon" source="media/doc-icon-sm.png" border="false"::: Learn more in the docs:
9495

9596
- [StorageFolder class](/uwp/api/windows.storage.storagefolder), [StorageFile class](/uwp/api/windows.storage.storagefile), [IStorageItem.IsOfType method](/uwp/api/windows.storage.istorageitem.isoftype)
96-
- [Access files and folders with Windows App SDK and WinRT APIs](../../../develop/files/winrt-files.md)
97+
- [Access files and folders with Windows App SDK and WinRT APIs](../../develop/files/winrt-files.md)
9798

9899
Now that the `AllNotes` model is ready to provide data for the view, you need to create an instance of the model in `AllNotesPage` so the view can access the model.
99100

@@ -165,7 +166,7 @@ Now that you've created `AllNotesPage`, you need to update `MainWindow.xaml` one
165166

166167
If you run the app now, you'll see that the note you created previously is loaded into the `ItemsView` control. However, it's just shown as the string representation of the object. The `ItemsView` doesn't know how this item should be displayed. You'll correct this in the next section.
167168

168-
:::image type="content" source="../media/all-notes/itemsview-no-template.png" alt-text="The notes app UI with the note list showing the Note class name instead of the note content.":::
169+
:::image type="content" source="media/all-notes/itemsview-no-template.png" alt-text="The notes app UI with the note list showing the Note class name instead of the note content.":::
169170

170171
### Add a data template
171172

@@ -233,11 +234,11 @@ When you use the `x:Bind` markup extension in a `DataTemplate`, you have to spec
233234

234235
When you run the app, the data template is applied to your `Note` items and looks like this if your Windows Personalization > Colors settings use the Light mode:
235236

236-
:::image type="content" source="../media/all-notes/itemsview-with-template.png" alt-text="The notes app UI with the note list showing the note content and date formatted by a data template.":::
237+
:::image type="content" source="media/all-notes/itemsview-with-template.png" alt-text="The notes app UI with the note list showing the note content and date formatted by a data template.":::
237238

238239
However, if your Windows Personalization > Colors settings use the Dark mode, it will look like this:
239240

240-
:::image type="content" source="../media/all-notes/itemsview-with-template-dark.png" alt-text="The notes app UI with a dark background but light gray note template.":::
241+
:::image type="content" source="media/all-notes/itemsview-with-template-dark.png" alt-text="The notes app UI with a dark background but light gray note template.":::
241242

242243
This is not the intended look for the app. It happened because there are hard-coded color values in the data template for the note. By default, WinUI elements adapt to the user's Dark or Light color preference. When you define you own elements, like a data template, you need to be careful to do the same.
243244

@@ -286,20 +287,23 @@ WinUI includes a variety of built-in resources that you can use to make your app
286287

287288
Now when you run the app with a Light color setting, it will look like this:
288289

289-
:::image type="content" source="../media/all-notes/itemsview-themed-template.png" alt-text="The notes app UI with a light background and light note template.":::
290+
:::image type="content" source="media/all-notes/itemsview-themed-template.png" alt-text="The notes app UI with a light background and light note template.":::
290291

291292
And when you run the app with a Dark color setting, it will look like this:
292293

293-
:::image type="content" source="../media/all-notes/itemsview-themed-template-dark.png" alt-text="The notes app UI with a dark background and dark note template.":::
294+
:::image type="content" source="media/all-notes/itemsview-themed-template-dark.png" alt-text="The notes app UI with a dark background and dark note template.":::
294295

295-
:::image type="icon" source="../media/doc-icon-sm.png" border="false"::: Learn more in the docs:
296+
:::image type="icon" source="media/doc-icon-sm.png" border="false"::: Learn more in the docs:
296297

297-
- [Item containers and templates](../../../design/controls/item-containers-templates.md)
298-
- [ResourceDictionary and XAML resource references](../../../develop/platform/xaml/xaml-resource-dictionary.md)
298+
- [Item containers and templates](../../design/controls/item-containers-templates.md)
299+
- [ResourceDictionary and XAML resource references](../../develop/platform/xaml/xaml-resource-dictionary.md)
299300

300301
> [!TIP]
301302
> The WinUI 3 Gallery app is a great way to learn about different WinUI controls and design guidelines. To see the theme resources used in the data template, [open the WinUI 3 Gallery app to the Color guidance](winui3gallery://item/Color). From there, you can see what the resources look like and copy the values you need directly from the app.
302303
>
303304
> You can also open the [Typography page](winui3gallery://item/Typography) and [Geometry page](winui3gallery://item/Geometry) to see other built-in resources used in this data template.
304305
305-
[!INCLUDE [winui-3-gallery](../../../../../hub/includes/winui-3-gallery.md)]
306+
[!INCLUDE [winui-3-gallery](../../../../hub/includes/winui-3-gallery.md)]
307+
308+
> [!div class="nextstepaction"]
309+
> [Continue to step 5 - Add navigation between pages](navigation.md)

hub/apps/tutorials/winui-notes/includes/intro.md renamed to hub/apps/tutorials/winui-notes/intro.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: WinUI Notes
3-
description: WinUI Notes
2+
title: WinUI Notes tutorial - Introduction
3+
description: WinUI Notes tutorial introduction.
44
author: jwmsft
55
ms.author: jimwalk
6-
ms.date: 03/26/2025
6+
ms.date: 09/02/2025
77
ms.topic: tutorial
88
ms.localizationpriority: medium
99
---
10+
# Create a WinUI app
1011

1112
This tutorial series demonstrates how to create a WinUI 3 app using XAML and C#. The app you'll create is a note app, where the user can create, save, and load multiple notes. You can download or view the code for this tutorial from the [GitHub repo](https://github.com/MicrosoftDocs/windows-topic-specific-samples/tree/winui-3/tutorials/winui-notes).
1213

@@ -30,11 +31,11 @@ The final application is shown below:
3031

3132
_AllNotesPage_
3233

33-
:::image type="content" border="false" source="../media/intro/final-all-notes.png" alt-text="Final screenshot of the notes app, showing three save notes.":::
34+
:::image type="content" border="false" source="media/intro/final-all-notes.png" alt-text="Final screenshot of the notes app, showing three save notes.":::
3435

3536
_NotePage_
3637

37-
:::image type="content" border="false" source="../media/intro/final-note.png" alt-text="Final screenshot of the notes app, showing a new blank note.":::
38+
:::image type="content" border="false" source="media/intro/final-note.png" alt-text="Final screenshot of the notes app, showing a new blank note.":::
3839

3940
## Create the Visual Studio project
4041

@@ -49,11 +50,14 @@ To begin this tutorial, you must create a WinUI 3 app project in Visual Studio u
4950
This tutorial uses features that are new in Windows App SDK 1.7. You must make sure the Windows App SDK NuGet package is updated to version 1.7 or later.
5051

5152
> [!IMPORTANT]
52-
> If you have not created a WinUI 3 project before, follow the steps in **[Start developing Windows apps](../../../get-started/start-here.md)** to make sure your dev environment and Visual Studio project are set up correctly.
53+
> If you have not created a WinUI 3 project before, follow the steps in **[Start developing Windows apps](../../get-started/start-here.md)** to make sure your dev environment and Visual Studio project are set up correctly.
5354
54-
When you run your blank app project (as outlined in [Start developing Windows apps](../../../get-started/start-here.md)), you should see an empty window that looks like this:
55+
When you run your blank app project (as outlined in [Start developing Windows apps](../../get-started/start-here.md)), you should see an empty window that looks like this:
5556

56-
:::image type="content" source="../media/intro/step-0.png" alt-text="The notes app window with a title bar and empty content area.":::
57+
:::image type="content" source="media/intro/step-0.png" alt-text="The notes app window with a title bar and empty content area.":::
5758

5859
> [!TIP]
5960
> You'll frequently refer to API reference docs and conceptual docs while building Windows apps. In this tutorial, you'll see links inline in the text, and in groups labeled, "Learn more in the docs:". These links are optional; you don't need to follow them to complete the tutorial. They're provided in case you want to make note of where to find the information you'll need when you start to create your own apps.
61+
62+
> [!div class="nextstepaction"]
63+
> [Continue to step 1 - Project setup](project.md)

hub/apps/tutorials/winui-notes/includes/navigation.md renamed to hub/apps/tutorials/winui-notes/navigation.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
2-
title: WinUI Notes 5
3-
description: WinUI Notes 5
2+
title: WinUI Notes -Step 5 - Navigation
3+
description: WinUI Notes - Step 5 - Add navigation between pages
44
author: jwmsft
55
ms.author: jimwalk
66
ms.date: 09/02/2025
77
ms.topic: tutorial
88
---
9+
# Navigate between pages
910

1011
This portion of the tutorial adds the final piece to the app, navigation between the _all notes_ page and the individual _note_ page.
1112

@@ -189,10 +190,19 @@ Next, you need to update the code in `NotePage` to navigate back after the note
189190

190191
Now you can run your app. Try adding new notes, navigating back and forth between notes, and deleting notes.
191192

192-
:::image type="icon" source="../media/doc-icon-sm.png" border="false"::: Learn more in the docs:
193+
:::image type="icon" source="media/doc-icon-sm.png" border="false"::: Learn more in the docs:
193194

194-
- [Implement navigation between two pages](../../../design/basics/navigate-between-two-pages.md)
195-
- [Navigation history and backwards navigation](../../../design/basics/navigation-history-and-backwards-navigation.md)
195+
- [Implement navigation between two pages](../../design/basics/navigate-between-two-pages.md)
196+
- [Navigation history and backwards navigation](../../design/basics/navigation-history-and-backwards-navigation.md)
196197
- [Frame class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.frame), [Page class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.page)
197198

199+
## Next steps
198200

201+
Congratulations! You've completed the _Create a WinUI app_ tutorial!
202+
203+
The following links provide more information about creating apps with WinUI and the Windows App SDK:
204+
205+
- [Samples and resources](/windows/apps/get-started/samples)
206+
- [Design for Windows apps](/windows/apps/design/)
207+
- [Develop Windows desktop apps](/windows/apps/develop/)
208+
- [Controls for Windows apps](/windows/apps/design/controls/)

hub/apps/tutorials/winui-notes/includes/note.md renamed to hub/apps/tutorials/winui-notes/note.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: WinUI Notes 2
3-
description: WinUI Notes 2
2+
title: WinUI Notes tutorial - Step 2 - Note page
3+
description: WinUI Notes tutorial - Step 2 - Create a page for a note.
44
author: jwmsft
55
ms.author: jimwalk
6-
ms.date: 03/26/2025
6+
ms.date: 09/02/2025
77
ms.topic: tutorial
88
no-loc: ["App.xaml", "App.xaml.cs", "MainWindow.xaml", "MainWindow.xaml.cs", "NotePage.xaml", "NotePage.xaml.cs"]
99
---
10+
# Create a page for a note
1011

1112
Now you'll create a page that allows a user to edit a note, and then you'll write the code to save or delete the note.
1213

@@ -68,7 +69,7 @@ First, add the new page to the project:
6869

6970
Let's break down the key parts of the XAML controls placed on the page:
7071

71-
:::image type="content" source="../media/note/app-layout.png" alt-text="The new note page UI with the grid highlighted by Visual Studio.":::
72+
:::image type="content" source="media/note/app-layout.png" alt-text="The new note page UI with the grid highlighted by Visual Studio.":::
7273

7374
- The [Grid.RowDefinitions](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.grid.rowdefinitions) and [Grid.ColumnDefinitions](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.grid.columndefinitions) define a grid with 2 rows and 3 columns (placed below the title bar).
7475
- The bottom row is automatically (`Auto`) sized to fit its content, the two buttons. The top row uses all the remaining vertical space (`*`).
@@ -86,10 +87,10 @@ Let's break down the key parts of the XAML controls placed on the page:
8687

8788
- Two `<Button>` controls are inside the `<StackPanel>` and arranged horizontally. You'll add the code to handle the buttons' [Click](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.primitives.buttonbase.click) events in the next section.
8889

89-
:::image type="icon" source="../media/doc-icon-sm.png" border="false"::: Learn more in the docs:
90+
:::image type="icon" source="media/doc-icon-sm.png" border="false"::: Learn more in the docs:
9091

91-
- [Responsive layouts with XAML](../../../design/layout/layouts-with-xaml.md)
92-
- [Layout panels](../../../design/layout/layout-panels.md)
92+
- [Responsive layouts with XAML](../../design/layout/layouts-with-xaml.md)
93+
- [Layout panels](../../design/layout/layout-panels.md)
9394
- [XAML namespaces and namespace mapping](/windows/uwp/xaml-platform/xaml-namespaces-and-namespace-mapping)
9495

9596
## Load and save a note
@@ -153,7 +154,7 @@ Now you're going to add code to the **NotePage.xaml.cs** code-behind file to han
153154
> [!IMPORTANT]
154155
> You need to mark this method with the `async` keyword because the file access calls are asynchronous. In short, if you call a method that ends in `...Async` (like `TryGetItemAsync`), you can add the [await](/dotnet/csharp/language-reference/operators/await) operator to the call. This keeps subsequent code from executing until the awaited call completes and keeps your UI responsive. When you use `await`, the method that you're calling from needs to be marked with the [async](/dotnet/csharp/language-reference/keywords/async) keyword. For more info, see [Call asynchronous APIs in C#](/windows/uwp/threading-async/call-asynchronous-apis-in-csharp-or-visual-basic).
155156

156-
:::image type="icon" source="../media/doc-icon-sm.png" border="false"::: Learn more in the docs:
157+
:::image type="icon" source="media/doc-icon-sm.png" border="false"::: Learn more in the docs:
157158

158159
- [Access files and folders with WinRT APIs](/windows/apps/develop/files/winrt-files)
159160
- [Call asynchronous APIs in C#](/windows/uwp/threading-async/call-asynchronous-apis-in-csharp-or-visual-basic)
@@ -164,7 +165,7 @@ Next, add the [Click](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.contr
164165

165166
1. In the **NotePage.xaml** file, place your cursor after the `Content` attribute in the **Save** `Button` control. Type `Click=`. At this point, Visual Studio should pop up an auto-complete UI that looks like this:
166167

167-
:::image type="content" source="../media/note/new-event-xaml.png" alt-text="A screenshot of the Visual Studio new event handler auto complete UI in the XAML editor":::
168+
:::image type="content" source="media/note/new-event-xaml.png" alt-text="A screenshot of the Visual Studio new event handler auto complete UI in the XAML editor":::
168169

169170
- Press the down-arrow key to select **\<New Event Handler>**, then press <kbd>Tab</kbd>. Visual Studio will complete the attribute with `Click="Button_Click"` and add an event handler method named `Button_Click` in the **NotePage.xaml.cs** code-behind file.
170171

@@ -182,12 +183,12 @@ Next, add the [Click](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.contr
182183
> [!TIP]
183184
> To locate code in your app, click **Search** in the Visual Studio title bar and use the **Code Search** option. Double-click the search result to open the code in the code editor.
184185
>
185-
> :::image type="content" source="../media/note/vs-code-search.png" alt-text="Search feature in Visual Studio":::
186+
> :::image type="content" source="media/note/vs-code-search.png" alt-text="Search feature in Visual Studio":::
186187

187188
1. Place your cursor before the "B" in `Button` and type `Save`. Wait a moment, and the method name will be highlighted in green.
188189
1. When you hover over the method name, Visual Studio will show a tooltip with a screwdriver or lightbulb icon. Click the down-arrow button next to the icon, then click **Rename 'Button_Click' to 'SaveButton_Click**'.
189190

190-
:::image type="content" source="../media/note/method-rename.png" alt-text="The Visual Studio method rename popup UI.":::
191+
:::image type="content" source="media/note/method-rename.png" alt-text="The Visual Studio method rename popup UI.":::
191192

192193
Visual Studio will rename the method everywhere in your app, including in the XAML file where you first added it to the `Button`.
193194
1. Repeat these steps for the **Delete** button, and rename the method to `DeleteButton_Click`.
@@ -294,3 +295,6 @@ With this code in place, you can test the app to make sure the note saves and lo
294295

295296
> [!IMPORTANT]
296297
> After you've confirmed that saving and deleting a note works correctly, create and save a new note again. You'll want to have a saved note to test the app in later steps.
298+
299+
> [!div class="nextstepaction"]
300+
> [Continue to step 3 - Add a view and model for the note](view-model.md)

0 commit comments

Comments
 (0)