xaml - 在 Xamarin 中添加自定义字体

标签 xaml xamarin resources custom-font xamarin.essentials

根据这篇文章: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/

相关文章:

c# - 如何在 Windows 8 XAML 应用程序中拖动元素?

c# - 如何从 xamarin 表单中的绑定(bind)命令调用函数

java - Runnable jar 使用 java -jar 运行良好,但双击时出现问题

c++ - 强制资源从非 mfc 应用程序中的 dll 加载的 WTL 方式? (我们使用的是 WTL/ATL,而不是直接的 win32)

ios - 在 iPhone 5 上尝试调试应用程序时出现 Xamarin iOS 错误

c - 在静态库中嵌入资源 - C/C++

wpf - 为什么这个触发器不触发?

wpf - 动态大小的 WPF 文本框的最大高度

c# - 将 UTC DateTime 转换为特定时区 xamarin forms pcl

c# - 构建后找不到已安装包的命名空间