I have downloaded a font from fonts.google.com and would like to set the font family for all labels in my Xamarin Forms app.
Adding the following code to all labels seems like an excessive amount of work
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.Android>Mogra-Regular.ttf#Mogra-Regular</OnPlatform.Android>
</OnPlatform>
</Label.FontFamily>
Ideally I would set the font family in the Resource Dictionary where I've already succesfully set text colour and font attributes, however, I've been unsuccesful in doing so.
I have managed to change the font family using a custom renderer but the moment I alter the label text colour or font attributes using dynamic resources the font family is reset to default.
Is there any way that will allow me to universally use my custom font and still be allowed to dynamically change other aspects of any given label?
Create an implicit Style (a Style without an x:Key
) in your App.xaml and it'll be applied to all Label
s
<Style TargetType="Label">
<Setter Property="FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.Android>Mogra-Regular.ttf#Mogra-Regular</OnPlatform.Android>
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With