Xamarin.Forms:是否有任何方法可以在XAML中以派生样式设置默认字体(family)



当基本标签样式设置为某些特定的字体家族时,我需要将(重置(字体样式设置为某些标签中的字体样式。即:

        <Style TargetType="Label">
            <Setter Property="FontFamily" Value="{StaticResource ThinFontFamily}" />
        </Style>

        <Style TargetType="Label" x:Key="MyCustomStyle">
            <Setter Property="FontFamily" Value="... to some default"></Setter>
        </Style>

当然还有另外两种方法:明确定义所有标签并使用自定义渲染器,但这就像很多代码。

平台默认字体家族可以在样式setter属性中设置为空值:

<Style x:Key="defaultLabel" TargetType="Label">
    <Setter Property="FontFamily" Value="" />
</Style>
...
<Label x:Name="label" Style="{StaticResource defaultLabel}"
       Text="{Binding Source={x:Reference label}, 
                      Path=Font, StringFormat='Default: {0}'}}" />

最新更新