Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Font changes once but never again

$
0
0

Hi,

I have two custom buttons. I set the font in the Android renderer like this

protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.SetBackgroundColor(Android.Graphics.Color.White);
                var font = Typeface.CreateFromAsset(Forms.Context.Assets, string.Format("Fonts/{0}", e.NewElement.FontFamily));
                Control.SetTypeface(font, TypefaceStyle.Normal);
            }
        }

This works fine.

When I click the button, I want to swap the fonts, so I sit on the OnPropertyChanged event to grab the property change.

protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (e.PropertyName == "FontFamily")
            {
                var btn = sender as CustomButton;
                var font = Typeface.CreateFromAsset(Forms.Context.Assets, string.Format("Fonts/{0}", btn.FontFamily));
                Control.SetTypeface(font, TypefaceStyle.Normal);
            }
        }

The event is hit and if I set a breakpoint on the Control line, the ben.FontFamily contains the name of the font I want to change it to. However, the font doesn't change.

I've tried running the font change on the UI thread which makes no difference. I've also tried to invalidate the Control to see if that helps. Makes no difference.

Do I need to be doing something on the content page to update the buttons so the font change is reflected or have I hit a bug?

Paul


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>