根据这篇文章:https://devblogs.microsoft.com/xamarin/embedded-fonts-xamarin-forms/
添加自定义字体的新方法是将字体添加为嵌入资源,然后在 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)
最佳答案
ExportFontAttribute
位于 Xamarin.Forms
命名空间中,因此请确保您拥有
using Xamarin.Forms;
关于xaml - 在 Xamarin 中添加自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61147785/