【问题标题】:Xamarin.Forms: Is there any way to set default Font (Family) in derived style in xaml?Xamarin.Forms:有没有办法在 xaml 中以派生样式设置默认字体(家族)?
【发布时间】:2018-08-06 23:28:18
【问题描述】:

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

        <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 中使用它。
  • 创建自定义标签类。它应该有你的自定义字体,默认标签有默认字体。反之亦然

标签: xaml xamarin.forms styles cross-platform


【解决方案1】:

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

<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}'}}" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 2011-04-15
    • 2016-07-16
    • 1970-01-01
    • 2018-07-23
    相关资源
    最近更新 更多