Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to set font family to whole application?

KhosrouKhosrou Member ✭✭✭

Hi guys,

I have added a custom font in my app and want to set it as the default font to the whole app.
Any suggestions on how to do this? I tried a lot, for example making a style in ResourceDictionary and target the Label control, but no result.
It works when I set it to individual controls on a page, but i want to implement it to the whole application. Please help!

Regards,
Khos

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    You could specify the global styles for the controls involved in the application in App.xaml. Then consume the style for these controls in each page.

    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="Label">
                <Setter Property="FontFamily" Value="sans-serif" />
                <Setter Property="FontSize" Value="20" />
            </Style>
            ...
        </ResourceDictionary>
    
    </Application.Resources>
    

    Check the tutorial:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/application

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Khosrou said:
    Hi guys,

    I have added a custom font in my app and want to set it as the default font to the whole app.
    Any suggestions on how to do this? I tried a lot, for example making a style in ResourceDictionary and target the Label control, but no result.
    It works when I set it to individual controls on a page, but i want to implement it to the whole application. Please help!

    Regards,
    Khos

    Yes, what @Jarvan said is the right solution. You will have to define the global style for each control view that you are using. Once set it the global style is automatically consumed when you use that control.

Sign In or Register to comment.