Microsoft-ui-xaml: [Feature] x:Bind should support general string indexers without interface in C#

Created on 6 Aug 2020  ·  6Comments  ·  Source: microsoft/microsoft-ui-xaml

Describe the bug
The documentation for x:Bind here in the 'path to the function' section specifies:

The path to the function is specified like other property paths and can include dots (.), indexers or casts to locate the function.

However, it appears that non-integer based indexers, e.g. strings, are not supported?

I was trying to bind directly to a Graph function with the Windows Community Toolkit's GraphPresenter:

RequestBuilder="{x:Bind providers:ProviderManager.Instance.GlobalProvider.Graph.Teams['<guid here>'].Channels['<guid thing here>'].Messages, Mode=OneWay}"

As these classes use string indexers to build the query to the Graph, E.g.

ITeamRequestBuilder this[string id] { get; }

However VS tells me in the x:Bind expression that I have provided an "invalid index value" and "WMC1110: Invalid binding path ... Unexpected array indexer".

Expected behavior
I would have expected string indexers to work just as I can pass them into function parameters with x:Bind in single-quotes.

Version Info
NuGet package version: WUX


| Windows 10 version | Saw the problem? |
| :--------------------------------- | :-------------------- |
| Insider Build (xxxxx) | |
| May 2020 Update (19041) | Yes |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) | |


| Device form factor | Saw the problem? |
| :----------------- | :--------------- |
| Desktop | Yes |
| Xbox | |
| Surface Hub | |
| IoT | |

area-Binding feature proposal team-Markup

All 6 comments

FYI @oldnewthing even showed a string indexer as an example in his article here in the opening paragraph:

<TextBlock Text=”{x:Bind Players[‘John Smith’]” />

Thanks @chingucoding for the article link! 🦙❤

@michael-hawker As he quoted from the documentation, here's the official part: https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/x-bind-markup-extension#collections

Thanks @Felix-Dev, @chingucoding just pointed me to that doc as well. I think the "functions in x:Bind doc" should link to the main article, I'll open up a doc issue about that.

So it seems like this is a feature request then as this is currently expected behavior as documented. Just not looking at the right doc... 😋

As noted in the documentation, the collection must be mutable. But your indexer is read-only.

(Note that IReadOnlyDictionary<T> and IMapView<T> do not support the indexer syntax.)

@StephenLPeters I understand that this was not intended as designed originally, but this is still a feature request.

Is there a reason the collection needs to be mutable to support this feature? Can we get a few more details here? I know it'll still need WinUI 3 to be fixed most likely in the future, if possible.

Thanks!

@StephenLPeters I understand that this was not intended as designed originally, but this is still a feature request.

Is there a reason the collection needs to be mutable to support this feature? Can we get a few more details here? I know it'll still need WinUI 3 to be fixed most likely in the future, if possible.

Thanks!

Sorry the triage team interpretated the conversation differently. We can reuse this as a feature proposal

Was this page helpful?
0 / 5 - 0 ratings