FontFamily defined in XAML per platform

后端 未结 1 1915
借酒劲吻你
借酒劲吻你 2021-01-14 16:02

In my Xamarin Forms project I would like to define the Form family onect per platform and the use that in the application.

So far I\'ve hardcoded the FontFamily per

相关标签:
1条回答
  • 2021-01-14 16:26

    Define a style in the App.xaml and then reference that style throughout the app. That way you can set the font once in the App.xaml using the OnPlatform tag and never have to worry about OnPlatform in all your other XAML files.

    <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="PlatformFontSample.App">
        <Application.Resources>
            <ResourceDictionary>
                <OnPlatform x:Key="FontFamilyName" x:TypeArguments="x:String" iOS="MarkerFelt-Thin" Android="OpenSans" WinPhone="Segoe UI" />
                <Style x:Key="FontLabel" TargetType="Label">
                    <Setter Property="FontFamily" Value="{DynamicResource FontFamilyName}" />
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    

    And then:

    <Label Text="{Binding Name}" Style="{DynamicResource FontLabel}" FontSize="Medium" FontAttributes="Bold" LineBreakMode="NoWrap"/>
    
    0 讨论(0)
提交回复
热议问题