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

Binding with Converter and ConverterParameter is not working at *2.5.1.317207-pre1* in some case on iOS. #2042

Closed
Szymaniuk opened this Issue Mar 7, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@Szymaniuk
Copy link

Szymaniuk commented Mar 7, 2018

Description

Binding with Converter and ConverterParameter is not working at 2.5.1.317207-pre1 in some case on iOS.
On Android there is no problem.
The problem occurs only on iOS - working fine at Xamarin Forms 2.5.0.280555, didn't work correctly at Xamarin Forms 2.5.1.317207-pre1.

The "tricky" thing, that is inside MainPage.xaml is mainly implemented, because of lack of possibility to Bind something directly into ConverterParameter - https://forums.xamarin.com/discussion/comment/283081/#Comment_283081

<Label x:Name="CustomObjectTypeKey" Text="{Binding CustomObjectType}"/>
<Label Text="{Binding Path=BindingContext.ValueAtWholeVmLevel, Source={x:Reference MainPageView}, Converter={StaticResource MyConverter}, ConverterParameter={x:Reference CustomObjectTypeKey}}"/>

So I'm defining CustomObjectTypeKey (which actually is hidden for the business needs), and using this Label.Text only for the next Label at ConverterParameter - because no able to do something like:
<Label Text="{Binding Path=BindingContext.ValueAtWholeVmLevel, Source={x:Reference MainPageView}, Converter={StaticResource MyConverter}, ConverterParameter=**{Binding CustomObjectType}**}"/>

It's working correctly at different customer views, at different business cases, but starting from 2.5.1.317207-pre1 it's just stops working on iOS - inside MyConverter, hackyBindedKeyLabel.Text field is NULL only on iOS and only on this XF release.

Steps to Reproduce

  1. Unpack attached App2.zip repo
  2. Run project on any iOS simulator (by default it's Xamarin Forms 2.5.0.280555)
  3. You will see page with ListView with values like:

_SomeCustomObject 1 - CustomObjectType
ValueAtWholeVmLevel value hackyBindedKeyLabel.Text is NULL at iOS at 2.5.1.317207-pre1 SomeCustomObject 1 - CustomObjectType

_SomeCustomObject 2 - CustomObjectType
ValueAtWholeVmLevel value hackyBindedKeyLabel.Text is NULL at iOS at 2.5.1.317207-pre1 SomeCustomObject 2 - CustomObjectType

  1. Update Xamarin Forms nuget to latest pre-release 2.5.1.317207-pre1
  2. Run project on any iOS simulator again
  3. You will see list with values like:

_SomeCustomObject 1 - CustomObjectType
ValueAtWholeVmLevel value hackyBindedKeyLabel.Text is NULL at iOS at 2.5.1.317207-pre1

_SomeCustomObject 2 - CustomObjectType
ValueAtWholeVmLevel value hackyBindedKeyLabel.Text is NULL at iOS at 2.5.1.317207-pre1

So the SomeCustomObject X - CustomObjectType part is missing.

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue: 2.5.1.317207-pre1

  • Last known good version: 2.5.0.280555

  • IDE: Visual Studio for Mac

  • Platform Target Frameworks:

    • iOS: 11.2
    • Android: 8.1
  • Android Support Library Version: N/A

  • Nuget Packages: Xamarin.Forms.2.5.1.317207-pre1.nupkg

  • Affected Devices:

Screenshots

2.5.0.280555 OK:
xf_2 5 0 280555

2.5.1.317207-pre1 NOK:
xf_2 5 1 317207-pre1

Reproduction Link

App2.zip

@pauldipietro pauldipietro added this to New in Triage Mar 7, 2018

@Szymaniuk Szymaniuk changed the title Binding with Converter and ConverterParameter is not working currectly in some case on iOS. Binding with Converter and ConverterParameter is not working currently in some case on iOS. Mar 7, 2018

@Szymaniuk Szymaniuk changed the title Binding with Converter and ConverterParameter is not working currently in some case on iOS. Binding with Converter and ConverterParameter is not working at *2.5.1.317207-pre1* in some case on iOS. Mar 7, 2018

@StephaneDelcroix

This comment has been minimized.

Copy link
Member

StephaneDelcroix commented Mar 7, 2018

looks like a dupe of #2019

Triage automation moved this from New to Closed Mar 7, 2018

@Szymaniuk

This comment has been minimized.

Copy link
Author

Szymaniuk commented Mar 8, 2018

@StephaneDelcroix partially could be duplicate - #2019 also occurs on iOS only and also on the same XF version, also inside ListView, but for Commands + CommandParameter vs for me for Converter + ConverterParameter .

@Szymaniuk

This comment has been minimized.

Copy link
Author

Szymaniuk commented May 10, 2018

@StephaneDelcroix it's just simply NOT WORKING starting from 2.5.1.317207-pre1 including newest 3.1.0.469394-pre1, so it's probably something really affected behind.

Please see this issue, attached reproduction project code.

@StephaneDelcroix

This comment has been minimized.

Copy link
Member

StephaneDelcroix commented May 23, 2018

This has to do with the order in which Bindings are applied, and that order was never guaranteed. It's not really a bug, it's more like if the hack you were relying on no longer works

you can fix this in your code by either:

  • subclassing Label, adding 2 bindableproperties. bind one to BindingContext.ValueAtWholeVmLevel, the other to CustomObjectType and when one of the value changes, update the Label.Text
  • without subclassing, add attachedBindableProperties to your Label, and again do the conversion there

this way, by having 2 bindable properties, you're sure to update the text regardless of the order the the Bindings are updated.

you could also

  • add a converter to the first Label, taking the 2nd one as parameter, and update the 2nd label when the first one changes. This is a bit more dirty, but will be faster to implement given the code you already have.

Triage automation moved this from Reopened to Closed May 23, 2018

@samhouts samhouts removed this from Closed in Triage Jun 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.