|
1 | 1 | --- |
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. |
4 | 4 | author: jwmsft |
5 | 5 | ms.author: jimwalk |
6 | | -ms.date: 03/26/2025 |
| 6 | +ms.date: 09/02/2025 |
7 | 7 | ms.topic: tutorial |
8 | 8 | no-loc: ["NotePage.xaml", "NotePage.xaml.cs", "Note.cs", "AllNotesPage.xaml", "AllNotes.cs", "WinUI 3 Gallery"] |
9 | 9 | --- |
| 10 | +# Add a view and model for all notes |
10 | 11 |
|
11 | 12 | This portion of the tutorial adds a new page to the app, a view that displays all of the notes previously created. |
12 | 13 |
|
@@ -88,12 +89,12 @@ The new data model represents the data required to display multiple notes. Here, |
88 | 89 |
|
89 | 90 | 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. |
90 | 91 |
|
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. |
92 | 93 |
|
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: |
94 | 95 |
|
95 | 96 | - [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) |
97 | 98 |
|
98 | 99 | 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. |
99 | 100 |
|
@@ -165,7 +166,7 @@ Now that you've created `AllNotesPage`, you need to update `MainWindow.xaml` one |
165 | 166 |
|
166 | 167 | 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. |
167 | 168 |
|
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."::: |
169 | 170 |
|
170 | 171 | ### Add a data template |
171 | 172 |
|
@@ -233,11 +234,11 @@ When you use the `x:Bind` markup extension in a `DataTemplate`, you have to spec |
233 | 234 |
|
234 | 235 | 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: |
235 | 236 |
|
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."::: |
237 | 238 |
|
238 | 239 | However, if your Windows Personalization > Colors settings use the Dark mode, it will look like this: |
239 | 240 |
|
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."::: |
241 | 242 |
|
242 | 243 | 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. |
243 | 244 |
|
@@ -286,20 +287,23 @@ WinUI includes a variety of built-in resources that you can use to make your app |
286 | 287 |
|
287 | 288 | Now when you run the app with a Light color setting, it will look like this: |
288 | 289 |
|
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."::: |
290 | 291 |
|
291 | 292 | And when you run the app with a Dark color setting, it will look like this: |
292 | 293 |
|
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."::: |
294 | 295 |
|
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: |
296 | 297 |
|
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) |
299 | 300 |
|
300 | 301 | > [!TIP] |
301 | 302 | > 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. |
302 | 303 | > |
303 | 304 | > 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. |
304 | 305 |
|
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) |
0 commit comments