Bug 51631 - Effect doesn't work with binding
Summary: Effect doesn't work with binding
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-01-19 07:07 UTC by AlexvanB
Modified: 2017-06-22 09:52 UTC (History)
5 users (show)

Tags: AC ios
Is this bug a regression?: ---
Last known good build:


Attachments
Testcase (16.47 KB, application/zip)
2017-02-01 09:25 UTC, AlexvanB
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description AlexvanB 2017-01-19 07:07:47 UTC
Because we have our own fonts and accessibility sizing I made effects to render label text, this works for hard coded text but not for text injected via binding.

Works
        <Label Text="Title" Style="{StaticResource BodyTextStyle}" >
            <Label.Effects>
                <local:BodyStyleFontEffect />
            </Label.Effects>
        </Label>

Does not work
        <Label Text="{Binding Title}" Style="{StaticResource BodyTextStyle}" >
            <Label.Effects>
                <local:BodyStyleFontEffect />
            </Label.Effects>
        </Label>
Comment 1 AlexvanB 2017-01-19 09:07:04 UTC
Workaround, in the effect force the property changed 

protected override void OnAttached ()
    {
        var preferredFont = UIFont.GetPreferredFontForTextStyle (new NSString (Constants.FontBodyIOS));
        var fontname = UIAccessibility.IsBoldTextEnabled ? Constants.FontBold : Constants.FontRegular;

        if (Element is Label) {
            var label = Control as UILabel;
            label.Font = UIFont.FromName (fontname, preferredFont.PointSize);

            Element.PropertyChanged += (sender, e) => {
                label.Font = UIFont.FromName (fontname, preferredFont.PointSize);
            };
Comment 2 Stephane Delcroix 2017-01-27 11:30:45 UTC
Could you please attach the simplest possible project triggering this issue so we could investigate ?

Thanks
Comment 3 AlexvanB 2017-02-01 09:25:24 UTC
Created attachment 19676 [details]
Testcase
Comment 4 Stephane Delcroix 2017-02-01 11:56:31 UTC
thanks
Comment 5 Stephane Delcroix 2017-05-31 09:28:50 UTC
it's not related to Binding, but to timing. changing the Label.Text after a short delay produce the same behavior.
Comment 6 Stephane Delcroix 2017-05-31 09:33:38 UTC
found it.

updating the Text resets text color and font.

https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs#L259
Comment 7 Samantha Houts [MSFT] 2017-06-08 17:12:48 UTC
https://github.com/xamarin/Xamarin.Forms/pull/950
Comment 8 Rui Marinho 2017-06-22 09:52:50 UTC
Should be fixed on 2.3.6-pre1