在Xamarin中添加自定义字体

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

据此帖子:https://devblogs.microsoft.com/xamarin/embedded-fonts-xamarin-forms/

添加自定义字体的新方法是将字体添加为EmbeddedResource,然后在App.xaml.ca中添加此行:

[assembly: ExportFont("DSEG7ModernRegular.ttf")]

但我收到此错误:

Error   CS0246  The type or namespace name 'ExportFontAttribute' could not be found (are you missing a using directive or an assembly reference?)

我的项目参考:

  • Xamarin.Essentials(1.3.1)
  • Xamarin.Forms(4.4.0.991265)-4.5
  • NetStandard.Library(2.0.3)
xaml xamarin resources custom-font xamarin.essentials
1个回答
0
投票

[ExportFontAttribute位于Xamarin.Forms命名空间中,因此请确保您具有

using Xamarin.Forms;
© www.soinside.com 2019 - 2024. All rights reserved.