Skip to content

Show how to bind to an IObservableMap with C++/WinRT #2077

@Holo-Krzysztof

Description

@Holo-Krzysztof

I'm having trouble binding to an IObservableMap instead of an IObservableVector, which works fine.

Binding to a single element of the map with indexer syntax in XAML works fine as well, but when I try to bind to the entire collection, I get HRESULT: 0x80070057 (E_INVALIDARG) when the ItemsSource property is set on load.

The documentation is contradictory here; the ItemsSource property page says:

The ItemsSource property value must implement one of these interfaces:
IIterable<IInspectable>
IBindableIterable

and according to C++/WinRT headers, IObservableMap<K, V> implements IIterable<IKeyValuePair<K, V>>, where IKeyValuePair<K, V> is an IInspectable, yet it doesn't work.

On the other hand the C++/WinRT collection docs say:

If you want to bind a XAML items control to your collection, then you can. 
But be aware that to correctly set the ItemsControl.ItemsSource property, you need to set it to a value of type IVector of IInspectable (or of an interoperability type such as IBindableObservableVector).

According to my experience so far, the C++/WinRT docs are right and the other page should be corrected.

On the other hand, I've tried doing the same with a C# Dictionary and it worked without a problem. I know the CLR is doing a lot of interop magic, but this shows me that it's indeed possible to bind to a map, so what exactly is going on there?

Metadata

Metadata

Assignees

Labels

Pri3doc-bugfeedback is about something that is out of date, unclear, confusing, or broken in the article

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions