Xamarin.forms: [Bug] Picker ItemDisplayBinding does not update correctly

Created on 13 Nov 2019  ·  6Comments  ·  Source: xamarin/Xamarin.Forms

Description

Using a standard Picker control:

<Picker Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand"
                Title="{i18n:Translate Verbindung}"
                ItemsSource="{Binding ListConnections}" 
                SelectedItem="{Binding SelectedConnection, Mode=TwoWay}"
                ItemDisplayBinding="{Binding Name, Mode=TwoWay}" />

The ItemDisplayBindingwill not update when the SelectedItemproperty changes from ViewModel (no user interaction with the control).

This worked last version (4.3.0.908675).
I keep the entire project constant, only the Xamarin.Forms nuget Package version is changed.

Edit: additional context upon further examination:

  • In my OnAppearing() hook, the properties
    ListConnections und SelectedConnectionare updated.
    The update to ListConnection happens first, and it calls the setter of the SelectedConnection property 3 times (number of elements in the list), 2 of which are null. These are not correctly handled by me, but the change seems to be that this propagated in a different fashion before ?!

Expected Behavior

UI reflects the change to the SelectedItem on the ItemDisplayBinding

Actual Behavior

ItemDisplayBinding is not updated (only when using Picker directly, not when setting property in code

Basic Information

  • Version with issue: *4.3.0.947036
  • Last known good version: 4.3.0.908675
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:

    • Android: 9.0
  • Nuget Packages:










  • Affected Devices:

  • All Android devices
regression Android needs-info ❓ unverified bug

All 6 comments

@Hottemax I am trying to reproduce this issue, but so far I have not been able to. I've attached my attempt below. I don't see any difference in behavior between 4.3.0.947036 and 4.3.0.908675. In both versions, the display name for the connection shows up in the Picker when selected.

Is there a detail I'm missing?

_8477 Repro.zip

@hartez Hi, thanks for your quick reply,

I have tested with the supplied repro, and it indeed works as expected.
The difference is it does NOT work with 4.1.0.709244, where your code sets it to null at every second button press at the end.

When we updated our project from 4.1.0.709244 -> 4.30.908765, it broke our code (because our code relied somehow implicitly on this false setter call at the end. So my initial comment about a bug introduced by 4.3.0.947036 was incorrect, sorry)

Maybe that was a bug that was fixed.
You can observe this unexpected behavior in your supplied solution when you set xamarin to 4.1.0.709244 ...

Thanks again for the quick answer...

MainPage.xaml.zip

4.1.709244

[0:] CLICK
[0:] SETTING LIST
[0:] LIST SET
[0:] SETTING CONNECTION
[0:] CALL TO SETTER Five
[0:] CONNNECTION SET
[0:] CALL TO SETTER null/FIVE <- _Alternating based on whether the Picker previously had a value_

4.3.0.947036

[0:] CLICK
[0:] SETTING LIST
[0:] LIST SET
[0:] SETTING CONNECTION
[0:] CALL TO SETTER Five
[0:] CONNECTION SET
[0:] CALL TO SETTER Five <- _Not exactly sure why there is another call (maybe because of TwoWay binding mode?!), but at least it is correct_

Hi @Hottemax

Just reading up on this issue, but I'm not sure... Is there anything expected from our side? :)

You seem to be saying that it works as intended now? If so, please feel free to close the issue.

If not, please let us know what we can do for you. Ideally, adapt the code from the reproduction project to show the issue and add it back here.

Thanks!

Hi @Hottemax

Just reading up on this issue, but I'm not sure... Is there anything expected from our side? :)

You seem to be saying that it works as intended now? If so, please feel free to close the issue.

If not, please let us know what we can do for you. Ideally, adapt the code from the reproduction project to show the issue and add it back here.

Thanks!

I was not sure if the original reporter is supposed to close it ...
Thanks for the swift and to-the-point handling of reported issues!

Hey, you are the one opening it, that gives you the right to do whatever your want with it 😉

Thanks for the kind words @Hottemax ! If there is anything else we can do for you, please let us know!

Was this page helpful?
0 / 5 - 0 ratings