-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] ListView item BindingContext unexpectedly changing #10437
Comments
I can reproduce the issue. Output example:
|
Any news on this?? On my project, it changes the BindingContext of the Items bound in the ListView to the Page.BindingContext, which, of course, breaks it, and is not the intended behavior. It happened only on UWP so far. Tested in Android, WPF and GTK. |
@MitchBomcanhao - You'll observe that the binding error happens on the parent control, not the item. There appears to be a bug in the way Xamarin binds where it first attempts to bind to the owner of the list (the ListView), then to the item in the list. I've been programming in WPF and UWP since the first pre-releases. This is a bug. This is not desired behavior and there's no scenario I can think of where this should be the default. I'm having trouble imagining a scenario where you'd want this at all. The triage people will first try to say "Well, it doesn't impact performance." How will you know if you don't remove the bug and then test it? If you take the time to remove the bug, then just release the fix. Even if I wanted to use the value from the Property on the ListView, you don't use it. Second, this bug makes it impossible to look for real binding bugs which can play havoc on a large, complex, MVVM application. |
What is the status with this bug? |
Any update on this? |
BUMP |
I thought I'd try creating a DataTemplateSelector with which I return a blank template (no bindings to fail) for an object of any inconsistent type. It was a right pain to create and didn't fix the issue because the objects passed through to the DataTemplateSelector was of the correct type but somewhere between selecting the template and binding it swapped the item for the ListView BindingContext anyway. |
Is there any update on this bug? It still happens on Xamarin UWP. Tried to use x:DataType, but it doesn't work
|
I can confirm bug on Xamarin UWP framework version 5.0.0.2012 . The bug doesn't occur on Android and iOS version. |
Does anyone know if this issue occurs on Xamarin.Forms 4.5.0.530 or if this is an issue with all of 4.5.x versions? |
unfortunately, 4.5.x versions and UWP appear to be incompatible. I can confirm the current latest version, 5.0.0.2012, still has the issue. I have found a work around though. If you add the model properties to the viewmodel, the binding errors will disappear. I'm taking a deeper dive into learning how bindings work.
|
This issue still seems to be open for Xamarin.Forms 5.0.0.2083 It seems like this issue about list views not being recycled could be related (just a wild guess). Can anyone confirm if this is still an issue in Xamarin.Forms 5.0.0.2083? |
Does anyone have an update on this? I have been fighting with a ListView for the last hour only to find out this is the issue. Not great. @rpetersonfujitsu I am seeing the same issue on Xamarin.Forms 5.0.0.2083. |
@Ruddy2007 i had this issue and solved it by moving from using XAML to using the new C# Fluent Markup with XamarinCommunityToolkit in preparation for MAUI big architecture change but totally worth it https://docs.microsoft.com/en-us/xamarin/community-toolkit/markup |
@confessore I cant switch over at this point I'm afraid. I can see the binding context changes from the object to the VM and back to the object... this is breaking the binding and nothing is updating after this. Any way to stop the binding from changed after the first one? I have been at this a while and cannot find a single workaround. |
Hello |
I am having similar issue on .Net Maui on Windows platform. Any update on this? |
Yeah, just wasted a few hours of my time chasing shadows because of this. Probably not even the first time. |
since maui is built on top of xamarin and the original xamarin team has departed microsoft, i would not expect this bug to be fixed internally by microsoft for many years. unsubscribing from this list |
Still seeing these spurious binding errors in MAUI .NET 6 |
Bump. |
Bump, just wasted a couple hours tracking this down in MAUI/.Net7. Please - just fix this. Why does the Windows member of the Android/iOS/Windows triad get the least love? |
Finally got here after a long search. The bare minimum would be a note in the documentation at least. |
This problem also breaks MAUI RelayCommands when binding a List Item to a CommandParameter using
This results in a runtime exception becasue {Binding .} initially returns the List, then the binding context changes to the List Item |
Description
This has been observed on UWP, have not been able to test on other platforms.
I've started noticing a lot of debug messages about binding errors on ui elements inside listview items.
After debugging a little, it seems that the list items get created twice - I've got 5 items on the list, but 2 sets of 5 items have been built.
The datatemplate selector has ran twice.
The first set of items have the correct binding context.
Then the second set uses the listview's bindingcontext first (which is wrong and causes binding errors) but then corrects itself to the item's bindingcontext.
This second set of items appears to be the one that gets displayed in the UI, judging by their unique ids.
this is the stack when the binding context changed event is fired for the wrong context
then it fires again, with this stack, and this comes with the correct binding context for the list item
Has anyone seen anything like this, any ideas on what is going on?
Basic Information
The text was updated successfully, but these errors were encountered: