【问题标题】:Adding a custom font in Xamarin在 Xamarin 中添加自定义字体
【发布时间】:2020-04-10 19:58:14
【问题描述】:

据此贴: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)

【问题讨论】:

  • “在这篇文章中,我们将了解如何在 Xamarin.Forms 4.5.530 及更高版本中使用它。”
  • 那么...那个版本在哪里??????
  • 我假设这是一个错字,他的意思是 4.5.0.530 - nuget.org/packages/Xamarin.Forms/4.5.0.530
  • 更新到 4.5.0.617 还是一样的问题...奇怪...
  • 它在该版本的发行说明中 - docs.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/…。它应该在主 Xamarin.Forms 命名空间中 - 我假设您在文件中有 using Xamarin.Forms;?您可以尝试重启 VS、清除 bin/obj 文件夹等常用技巧

标签: xaml xamarin resources custom-font xamarin.essentials


【解决方案1】:

ExportFontAttributeXamarin.Forms 命名空间中,所以请确保您有

using Xamarin.Forms;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-24
    • 2016-07-12
    • 2016-11-22
    • 2020-01-16
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多