-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
XAML bindings are flagging invalid binding failures in ListView - it is confused as to what the data context is... #8433
Comments
Hi, @mobycorp - Thank you for opening this issue. I understand that you may not be able to share your project, but would you be able to share a sample (in the form of a GitHub repository) that reproduces the issue you describe? That would help us tremendously in investigating this further and helping to debug this issue. |
Hi @mobycorp. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
I am currently on a severe deadline and barely have time to eat dinner, so, no. I cannot supply you with example code. I indicated as much from above. You guys are smart guys and should have no problem reproducing what I have reported. |
We tried to come up with a repro, based on the scarce info you gave us, but that repro is working well. I'm sorry about your severe deadlines, and the impact on your work-life balance. We understand the sense of urgency, and this is why you got quick answers. If you really need this investigated, you definitely have to provide the smallest possible project that triggers this behaviour, and we will look at it. Thanks |
Hi @mobycorp. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
I'm not trying to be difficult. I am on a tight deadline... And, Gerald, love your YouTube channel!! :-) The errors are triggered by the display of content in the listview in the picture. One per row x3 because there are three properties in the view model. I tried dereferencing the three properties so that:
becomes:
but this did not change anything. The errors are still being generated... @jfversluis, since I you didn't post the xaml you used to generate your example picture, I am not sure if you are doing things exactly like me. Did you create an item template that looks similar to the above. I know that HotReload NEVER works when I makes changes to code in a template and I am wondering if it is because of the item template... ??? This is my entire listview definition:
There are two things to note here:
Does any of that make sense? |
Thanks for the kind words, appreciate it! 😄 The XAML I used is in that sample repo I posted. I didn't link it up the right way here, but you should be able to see my full reproduction here: https://github.com/jfversluis/Repro8433 for the bits and pieces you posted that is what it boiled down to according to me. The thing that stands out in your opening post, is that the error states it's looking for the While reviewing your code I think I see what's up... Maybe. I see you set the x:DataType on the |
Hi @mobycorp. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@jfversluis You picked up on the exact issue that I am trying to describe.
Unless I don't understand fully what the x:DataType declaration does, I would think that would allow the parser to correctly map the properties in the detail view model (EmailViewModel) |
@jfversluis Some additional detail... This is the code-behind of the content page:
|
Here are the answers to your questions:
|
Ok, that is exactly what I supposed x:DataType did. So, when in the xaml editor and I type Email.Subject and no squiggly lines are there AND it was able to find the properties and properties of properties, I would expect it to NOT report binding errors. That is the basic crux of what I am reporting. |
If you remove the DataType in the ItemTemplate it will force the DataType you probably defined in your ContentPage expecting to find "Email" in EmailsViewModel, with "classic bindings" you should remove that too Anyway the error shouldn't allow you to compile so that seems a bit different from what is happening to you... As Gerald said, probably there's something about setting the DataType to the DataTemplate that gives you those errors at runtime |
I am experiencing the same issue and have created a repro here: If the collection property on the view model is set prior to setting the view model as the binding context I do not experience a binding error, but if I set the value of the collection property later (in this case via a delayed Loaded event handler) there are binding errors for each property on each item in the collection. Note that despite the binding errors it appears to be displaying correctly, though it does not respond to XAML hot reload. I have only tested the issue on the Windows platform. These errors occur both when the content of the ViewCell is in the initial page and also when it is in a separate ContentView |
I have the same problem here. My bindings work as expected, but the xaml compiler throws me error messages. However, I can launch and use the application as expected. The problem occurs in the ListView for me. |
I have this issue after I upgraded from .Net 7 to .Net 8 as well as the responsiveness of opening my page is much slower. |
Any news about the Problem? |
if you set the ItemsSource late, those Bindings Errors are normal, and expected, and should not prevent the proper display of the page. I believe there's no problem here, the error are genuine at the time they're produced. I'm closing this old bug, if you have an issue that affects the rendering of the page, please open a new issue |
How exactly is it normal and expected to get errors and break hot reload everytime you want to refresh your binding? Is it not allowed to set the ItemSource late? is it documented as such? I don't see how this issue is resolved in any way. |
Bindings Errors aren't crashing the app, are they ? They only show up in the log window, as a diagnostic. It is normal to see them if you set your context late, cause at the time, there's indeed an error But if you say HotReload breaks, there's indeed something to act on, and I'm reopenening this /cc @chabiss |
@StephaneDelcroix the binding failures are not caused by the app setting the binding context late. The ListView is set up properly, but something internal to MAUI seems to be setting the binding context late for each item. It's out of the developer's control. See my comment with a screenshot in this bug: This shouldn't affect hot reload though, so maybe something else is going on with hot reload. |
@StephaneDelcroix Hi, I think you can find more information here: #5511 (comment) |
@StephaneDelcroix @samhouts I'm going to add my voice to the others here - when I'm using list views, I constantly get binding errors in the log, even though it shows properly, and Hot Reload is touch and go under these circumstances. This is a serious issue for my project. |
Workaround to prevent the warnings (and InvalidCastExceptions):
|
Here is a generic solution to apply @MarcelWolterbeek 's solution CustomViewCell.xaml
CustomViewCell.xaml.cs
Then this can be used as:
|
Adding a +1 to this issue. The spam of warnings becomes quite unbearable when you have a list with a few hundred objects in it. |
Description
I have a list view which has its items source set to an observable collection in a top-level view model. The collection is a list of detail view models. I have explicitly set the data context in the item template to point to the detail view model, yet the error it flags indicates it is looking at the page's data context and not the context of a single element in the list. I hate to see any binding failures, but this one will not go away...
Here is the binding error listed (there are three, actually):
Here is the EmailsViewModel class:
And here is the EmailViewModel:
Looking at the xaml used to define the list view item template:
I am clearly setting the datatype for the item template to be of the EMAIL view model and NOT the EMAILS view model! Trust me when I say that the Email class DOES have the properties, SenderEmail.ShortName (from an EmailAddress class), Email.Subject, and Email.Message date.
So, why is the error pointing to the EmailsViewModel when I have set the datatype to be EmailViewModel? Intellisense works (which to my understanding is driven by the x:DataType property... I don't get it!
My code base has grown to a size where it is not feasible to give you a github repository, so the code snippets above will have to work.
Steps to Reproduce
I know you won't like this, but you will need to generate a simple app that has a listview with an itemtemplate defined as I listed above.
I can see no reason why these binding errors are being flagged....
Version with bug
6.0.400 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
net6.0-windows10.0.19041.0
Did you find any workaround?
No...
Relevant log output
No response
The text was updated successfully, but these errors were encountered: