Xamarin forms – Switch custom font on Style Trigger

Just a small reminder for myself.
I was actually unaware this was possible in XAML styling, but now that I know it can be done, I will be using this more often đŸ™‚ !

So assume you want to use a custom font in your Xamarin Forms app and you want to preset each Label control with it, you can define this in a Styles.xml like so:

But what do you do when your custom font has no build in Bold feature and you have to rely on a separate custom font for that?
Well, you can let your XAML style check for a trigger and swap the font!
It’s fairly easy, so the code will now look like:

And now each time you add the FontAttributes=”Bold” property to your Label control, it will use the correct font type!

Happy coding.

One thought on “Xamarin forms – Switch custom font on Style Trigger”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.