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

Picker ItemDisplayBinding doesn't work with compiled bindings #23989

Closed
davidortinau opened this issue Aug 2, 2024 · 4 comments · Fixed by #24530
Closed

Picker ItemDisplayBinding doesn't work with compiled bindings #23989

davidortinau opened this issue Aug 2, 2024 · 4 comments · Fixed by #24530
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-9.0.0-rc.2.24503.2 i/regression This issue described a confirmed regression on a currently supported version p/0 Work that we can't release without platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@davidortinau
Copy link
Contributor

davidortinau commented Aug 2, 2024

Description

When I use ItemDisplayBinding in 8.0.80 nightly or .NET 9 Preview 7, the picker doesn't populate as I'd expect.

Screenshot 2024-08-02 at 2 32 52 PM

I can get around it using a ToString override on the model, or by providing the x:DataType=models:VocabularyList.

The ContentPage does specify a x:DataType for the view model. This doesn't work:

<Picker x:Name="VocabPicker" 
    ItemsSource="{Binding VocabLists}"
    ItemDisplayBinding="{Binding Name}"                    
    SelectedItem="{Binding VocabList, Mode=TwoWay}" />

This does work:

<Picker x:Name="VocabPicker" 
    ItemsSource="{Binding VocabLists}"
    ItemDisplayBinding="{Binding Name, x:DataType=models:VocabularyList}"                    
    SelectedItem="{Binding VocabList, Mode=TwoWay}" />
Screenshot 2024-08-02 at 2 53 10 PM

Steps to Reproduce

https://github.com/davidortinau/SentenceStudio/blob/main/src/SentenceStudio/Pages/Lesson/LessonStartPage.xaml

My testing with the original code:

8.0.71 - Debug - Good
8.0.71 - Release - Good
8.0.80 - Debug - Sad
8.0.80 - Release - Good

Link to public reproduction project repository

No response

Version with bug

Nightly / CI build (Please specify exact version)

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.61 SR6.1

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

No response

Did you find any workaround?

Yes, as described

Relevant log output

No response

@davidortinau davidortinau added the t/bug Something isn't working label Aug 2, 2024
Copy link
Contributor

github-actions bot commented Aug 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@PureWeen PureWeen added this to the .NET 8 SR8 milestone Aug 2, 2024
@PureWeen PureWeen added p/0 Work that we can't release without area-xaml XAML, CSS, Triggers, Behaviors labels Aug 2, 2024
@PureWeen PureWeen modified the milestones: .NET 8 SR8, .NET 8 SR9 Aug 6, 2024
@PureWeen PureWeen added the i/regression This issue described a confirmed regression on a currently supported version label Aug 9, 2024
@samhouts samhouts added platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 platform/android 🤖 platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending labels Aug 12, 2024
@simonrozsival
Copy link
Member

simonrozsival commented Aug 14, 2024

This is likely caused by #22056 and it would also break with .NET 9 in Release mode where the binding would be compiled with the wrong source data type.

There is a mismatch between the declared x:DataType (<ContentPage ... x:DataType="lesson:LessonStartPageModel">) and the actual type of the binding context when the binding is applied (lesson:VocabularyList). Specifying the x:DataType for the binding is the right way to declare this binding going forward.

@StephaneDelcroix
Copy link
Contributor

I did some testing, on the net9.0 branch (but should be similar on 'main'):

  • ItemDisplayBinding is compiled if x:DataType is set on the {Binding}
  • isn't compiled otherwise (without warning)

so,

  • we shouldn't prevent the Binding to be applied if there's a DataType mismatch in this case...
  • we should issue a compilation-time warning before falling back if DataType is missing

StephaneDelcroix added a commit that referenced this issue Aug 29, 2024
- re-enable XC0022 and XC0023 as WarningsNotAsErrors
- do not consider thar x:DataType is inherited on Picker items

- fixes #23989
StephaneDelcroix added a commit that referenced this issue Aug 30, 2024
Picker.ItemDisplayBinding for example shouldn't inherit parent DataType

- fixes #23989
StephaneDelcroix added a commit that referenced this issue Aug 30, 2024
Picker.ItemDisplayBinding for example shouldn't inherit parent DataType

- fixes #23989
StephaneDelcroix added a commit that referenced this issue Aug 30, 2024
- re-enable XC0022 and XC0023 as WarningsNotAsErrors
- do not consider thar x:DataType is inherited on Picker items

- fixes #23989
@hungchips
Copy link

hungchips commented Aug 31, 2024

This is still happening on MAUI 8.0.82.
And even I did it this way:
<Picker x:Name="VocabPicker" ItemsSource="{Binding VocabLists}" ItemDisplayBinding="{Binding Name, x:DataType=models:VocabularyList}" SelectedItem="{Binding VocabList, Mode=TwoWay}" />

But it still doesn't show up even though the Source has data.

StephaneDelcroix added a commit that referenced this issue Sep 2, 2024
Picker.ItemDisplayBinding for example shouldn't inherit parent DataType

- fixes #23989
mattleibow pushed a commit that referenced this issue Sep 3, 2024
* [X] do not look for parent DataType on collections

- re-enable XC0022 and XC0023 as WarningsNotAsErrors
- do not consider thar x:DataType is inherited on Picker items

- fixes #23989

* fixtrimming
StephaneDelcroix added a commit that referenced this issue Sep 5, 2024
Picker.ItemDisplayBinding for example shouldn't inherit parent DataType

- fixes #23989
@PureWeen PureWeen modified the milestones: .NET 8 SR9, 9.0-rc2 Sep 10, 2024
@PureWeen PureWeen modified the milestones: 9.0-rc2, .NET 9.0 GA Sep 23, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in MAUI SDK Ongoing Sep 25, 2024
StephaneDelcroix added a commit that referenced this issue Oct 10, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
github-actions bot pushed a commit that referenced this issue Oct 15, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
PureWeen pushed a commit that referenced this issue Oct 16, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
github-actions bot pushed a commit that referenced this issue Oct 17, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
github-actions bot pushed a commit that referenced this issue Oct 17, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
github-actions bot pushed a commit that referenced this issue Oct 18, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152
PureWeen pushed a commit that referenced this issue Oct 18, 2024
Change the heuristic for deciding if we need ot ignore parent DataType,
as DataTrigger.Binding shoud inherit it, and
Picker.ItemDisplayNameBinding should not

this is an alternate fix for #23989, partially replaces #24513, and will
help fixing #25141 together with #24152

Co-authored-by: Stephane Delcroix <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-9.0.0-rc.2.24503.2 i/regression This issue described a confirmed regression on a currently supported version p/0 Work that we can't release without platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants