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

问题描述 投票:2回答:1

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

        <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>

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

xaml xamarin.forms styles cross-platform
1个回答
4
投票

可以在样式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}'}}" />
© www.soinside.com 2019 - 2024. All rights reserved.