Skip to content

Commit 98d1fa9

Browse files
authored
More info, and the kind of errors and behavior you can expect if you don't follow the advice here. (#5659)
1 parent ed686d1 commit 98d1fa9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

uwp/cpp-and-winrt-apis/binding-collection.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: A collection that can be effectively bound to a XAML items control is known as an *observable* collection. This topic shows how to implement and consume an observable collection, and how to bind a XAML items control to it.
33
title: XAML items controls; bind to a C++/WinRT collection
4-
ms.date: 04/24/2019
4+
ms.date: 08/04/2025
55
ms.topic: article
66
keywords: windows 10, uwp, standard, c++, cpp, winrt, projection, XAML, control, binding, collection
77
ms.localizationpriority: medium
@@ -40,8 +40,8 @@ runtimeclass BookstoreViewModel
4040
...
4141
```
4242

43-
> [!NOTE]
44-
> In the MIDL 3.0 listing above, note that the type of the **BookSkus** property is [**IObservableVector**](/uwp/api/windows.foundation.collections.ivector_t_) of **BookSku**. In the next section of this topic, we'll be binding the items source of a [**ListBox**](/uwp/api/windows.ui.xaml.controls.listbox) to **BookSkus**. A list box is an items control, and to correctly set the [**ItemsControl.ItemsSource**](/uwp/api/windows.ui.xaml.controls.itemscontrol.itemssource) property, you need to set it to a value of type **IObservableVector**, or **IVector**, or of an interoperability type such as [**IBindableObservableVector**](/uwp/api/windows.ui.xaml.interop.ibindableobservablevector).
43+
> [!IMPORTANT]
44+
> Binding to a collection with C++/WinRT is a little more nuanced than it is with C#. In the MIDL 3.0 listing above, note that the type of the **BookSkus** property is [**IObservableVector**](/uwp/api/windows.foundation.collections.ivector_t_) of **BookSku**. In the next section of this topic, we'll be binding the items source of a [**ListBox**](/uwp/api/windows.ui.xaml.controls.listbox) to **BookSkus**. A list box is an items control, and to correctly set the [**ItemsControl.ItemsSource**](/uwp/api/windows.ui.xaml.controls.itemscontrol.itemssource) property, you need to set it to a value of type **IObservableVector**, or **IVector**, or of an interoperability type such as [**IBindableObservableVector**](/uwp/api/windows.ui.xaml.interop.ibindableobservablevector). Otherwise, `{x:Bind}` will generate **E_INVALIDARG**, and `{Binding}` will fail silently.
4545
4646
> [!WARNING]
4747
> The code shown in this topic applies to C++/WinRT version 2.0.190530.8 or later. If you're using an earlier version, then you'll need to make some minor tweaks to the code shown. In the MIDL 3.0 listing above, change the **BookSkus** property to [**IObservableVector**](/uwp/api/windows.foundation.collections.ivector_t_) of [**IInspectable**](/windows/desktop/api/inspectable/nn-inspectable-iinspectable). And then use **IInspectable** (instead of **BookSku**) in your implementation, too.

0 commit comments

Comments
 (0)