Xamarin.Forms:有没有办法在 xaml 的派生样式中设置默认字体(系列)?

Aga*_*gat 3 xaml styles cross-platform xamarin.forms

当基本标签样式设置为某些特定字体系列时,我需要在某些标签(例如)中将(重置)字体样式设置为默认值。IE:

        <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>
Run Code Online (Sandbox Code Playgroud)

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

Ben*_*enl 6

平台默认字体系列可以在样式设置器属性中设置为空值:

<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}'}}" />
Run Code Online (Sandbox Code Playgroud)