I want to use custom font in xaml
file in xamarinforms on the portable folder(not iOS and android) that get an output for all of this platform.
If you don't want do implement this on your own, you can use the CustomFontEffect
we added in the CommunityToolkit for Xamarin forms : https://github.com/FormsCommunityToolkit/FormsCommunityToolkit/tree/dev/src
There is an example project added but overal usage is as follows:
<Label Text="Comic Sans is tha bomb!">
<Label.Effects>
<effects:CustomFontEffect FontPath="ComicSaaaaaans.ttf" FontFamilyName="Comic Sans MS" />
</Label.Effects>
</Label>
Create a font style that reflects on your platform like:
<OnPlatform x:Key="NormalFont" x:TypeArguments="x:String"
iOS="Montserrat" Android="Montserrat"
WinPhone="Assets/Fonts/Montserrat-Regular.ttf#Montserrat"/>
use it with any of below options:
Direct using :
<Label Text="test" FontFamily="{StaticResource NormalFont}"/>
Using With anonymous style (that affects all labels in your app):
<Style TargetType="Label">
<Setter Property="FontFamily" Value="{StaticResource NormalFont}"/>
</Style>
Use with named Style:
<Style x:Key="TitleStyle" TargetType="Label">
<Setter Property="FontFamily" Value="{StaticResource Boldfont}"/>
</Style>
<Label Text="Options" Style="{StaticResource TitleStyle}"/>