Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Allow binding scopes in x:Bind #2237

Open
weitzhandler opened this issue Apr 6, 2020 · 5 comments
Open

Proposal: Allow binding scopes in x:Bind #2237

weitzhandler opened this issue Apr 6, 2020 · 5 comments
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team

Comments

@weitzhandler
Copy link
Contributor

Hi,

I used to set the DataContext to deeper scopes whenever necessary, so I can use shorter binding expressions: (ViewModel is of type ContactViewModel, that exposes a Phones collection property):

<Page DataContext="{Binding ViewModel}">
  <ListView ItemsSource="{Binding Phones}"/>
</Page>

I'm trying to use the above with x:Bind as follows, but seems that x:Bind would always bind against the page, not the current DataContext scope, which can lead to very verbose expressions.
My suggestion is that you allow scoping of x:Bind as well.

<Page DataContext="{x:Bind ViewModel}">
  <ListView ItemsSource="{x:Bind Phones}"/>
</Page>

But I get the following error:

XLS0432: The property 'Phones' was not found in type 'ContactsPage'. | MyProject.Client.UWP

Cross posted from here.

@weitzhandler weitzhandler added the feature proposal New feature proposal label Apr 6, 2020
@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Apr 6, 2020
@ranjeshj ranjeshj added the team-Markup Issue for the Markup team label Apr 6, 2020
@stevenbrix
Copy link
Contributor

This seems like it would require a fundamental difference in design for {x:Bind}.

How do you propose we enable this to happen?

@MikeHillberg
Copy link
Contributor

Haven't thought about syntax, but it feels like some kind of a let clause scenario.

@stevenbrix
Copy link
Contributor

As the user sees things, x:Bind doesn't use DataContext - that is what I was referring to about the fundamental difference in design.

Now we want to add a mode where it does bind to DataContext in some scenarios, but in others it uses the Page/UserControl.

I'm all for this, just not sure how to rationalize it in a way that doesn't cause things to blow up in complexity

@ranjeshj
Copy link
Contributor

Propagating DataContext down the tree is quite expensive. If we can selectively propagate and scope down the tree explicitly using x:Bind, that would be great. In this specific scenario would x:Bind ViewModel.Phones work ?

@michael-hawker
Copy link
Collaborator

🦙 This is related to #2508 as well I think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

7 participants