Skip to content

Commit 279618f

Browse files
committed
Fix usage of Resources in WinUI Window
1 parent e4e789f commit 279618f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

hub/apps/develop/data-binding/data-binding-overview.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ First, here's the [**SelectedItem**](/windows/windows-app-sdk/api/winrt/microsof
205205
</Window>
206206
```
207207

208-
For the [**CollectionViewSource**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.data.collectionviewsource) technique, first add a `CollectionViewSource` as a window resource.
208+
For the [**CollectionViewSource**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.data.collectionviewsource) technique, first add a `CollectionViewSource` as a resource of the top-level `Grid`.
209209

210210
``` xaml
211-
<Window.Resources>
211+
<Grid.Resources>
212212
<CollectionViewSource x:Name="RecordingsCollection" Source="{x:Bind ViewModel.Recordings}"/>
213-
</Window.Resources>
213+
</Grid.Resources>
214214
```
215215

216216
And then adjust the bindings on the [**ListView**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.listview) (which no longer needs to be named) and on the details view to use the [**CollectionViewSource**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.data.collectionviewsource). Note that by binding the details view directly to the `CollectionViewSource`, you're implying that you want to bind to the current item in bindings where the path cannot be found on the collection itself. There's no need to specify the `CurrentItem` property as the path for the binding, although you can do that if there's any ambiguity).
@@ -262,12 +262,13 @@ public class StringFormatter : Microsoft.UI.Xaml.Data.IValueConverter
262262
}
263263
```
264264

265-
Now we can add an instance of `StringFormatter` as a page resource and use it in the binding of the `TextBlock` that displays the `ReleaseDateTime` property.
265+
Now we can add an instance of `StringFormatter` as a resource and use it in the binding of the `TextBlock` that displays the `ReleaseDateTime` property.
266266

267267
``` xaml
268-
<Window.Resources>
268+
<Grid.Resources>
269+
...
269270
<local:StringFormatter x:Key="StringFormatterValueConverter"/>
270-
</Window.Resources>
271+
</Grid.Resources>
271272
...
272273
<TextBlock Text="{Binding ReleaseDateTime,
273274
Converter={StaticResource StringFormatterValueConverter},

0 commit comments

Comments
 (0)