首页 > 解决方案 > 添加了 FontFamily 但 Xamarin 中没有变化

问题描述

我正在尝试在我的 Xamarin 应用程序中使用 FontFamily。我下载了字体并将其添加到项目中,但仍未对文本进行更改。

Mobile.App字体(文件夹)

catamaran-regular.tff

移动应用程序AssemblyInfo.cs

using Xamarin.Forms;

[assembly: ExportFont("catamaran-regular.ttf")]

移动应用程序应用程序.xml

<Style
    TargetType="Label"
    ApplyToDerivedTypes="true">
    <Setter Property="FontFamily" Value="catamaran-regular" />
</Style>

Mobile.App.ViewsPage.xml

Label
    Text="Hello World!"
    FontSize="18"
    FontFamily="catamaran-regular">
</Label>

标签: c#.netxamarinxamarin.forms

解决方案


尝试使用别名来定位字体:

[assembly: ExportFont("catamaran-regular.ttf", Alias = "CatamaranRegular")]

然后在你的元素中使用别名:

<Label
    Text="Hello World!"
    FontSize="18"
    FontFamily="CatamaranRegular">
</Label>

如果仍然不起作用,请确保将字体设置为嵌入资源;如果您使用的是 Visual Studio,请选择该文件,然后从属性面板中选择“构建操作”下拉列表中的选项:

嵌入式资源


推荐阅读