什么是默认字体系列? [英] What's the default font family?

查看:158
本文介绍了什么是默认字体系列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将返回null:

DefaultFontFamily = Font.SystemFontOfSize(NamedSize.Default).FontFamily;

还有这个:

DefaultFontFamily = new Label().FontFamily;

什么是正确的方法?

推荐答案

没有正确的方法-因为这里没有跨平台的默认字体家族",而且事实是特定于平台.

There is no right way to do it - as there is no cross-platform 'default font family' to pull up here and, also the fact that it is platform specific.

要对此进行详细说明,请参考在

To elaborate on this further, would like to refer this property as defined in source code for Label,

public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty;

依次引用 FontElement

public static readonly BindableProperty FontFamilyProperty =
        BindableProperty.Create("FontFamily", typeof(string), typeof(IFontElement), default(string),
                                propertyChanged: OnFontFamilyChanged);

或您为 SystemFontOfSize .

public static Font SystemFontOfSize(NamedSize size)
{
    var result = new Font { NamedSize = size };
    return result;
}

如您所见,在两种情况下,按照源代码,

FontFamily的值'null'并非意外. (在第一种情况下,将依赖项属性定义为默认值default(string),该默认值会转换为null,在第二种情况下,永远不会设置FontFamily的值)

As you can see, in both cases, as per source code, the value 'null' for FontFamily is not unexpected. (In first case, the dependency property is defined with default value as default(string) which translates to null, and in second case, value for FontFamily is never set)

Font.Default也一样.在进一步挖掘时,您会遇到 ,其定义如下:

Same goes for Font.Default. On further digging, you come across IsDefault which is defined as following:

public bool IsDefault
{
    get { return FontFamily == null && FontSize == 0 && NamedSize == NamedSize.Default && FontAttributes == FontAttributes.None; }
}

因此,如果FontFamilynull,则它是xamarin形式生态系统中的默认值 .

So if FontFamily is null, then it is the default in xamarin forms eco-system.

Label确实在特定平台上呈现时,除非将其FontFamily属性专门从'null'修改为某个值,否则本机控件上的font属性也不会被修改.因此,本机控件使用该平台的默认字体系列呈现.

When Label does get rendered on a particular platform, then unless its FontFamily property is specifically modified from 'null' to some value, the font property on the native control is never modified either. So the native control is rendered with default font family for that platform.

为了获得该默认字体,您将必须实施本机服务,并使用依赖项注入获得该值.

In order to get that default font you will have to implement native-services, and use dependency-injection to get that value.

有关用于Label的本机控件的更多详细信息-您可以参考以下

For more details on native controls used for Label - you can refer this link.

这篇关于什么是默认字体系列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆