2

According to this post: https://devblogs.microsoft.com/xamarin/embedded-fonts-xamarin-forms/

The new way to add a custom font is to add the font as an embeddedResource and then add this line in App.xaml.ca:

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

But I get this error:

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

My project references:

  • Xamarin.Essentials (1.3.1)
  • Xamarin.Forms (4.4.0.991265) - 4.5
  • NetStandard.Library (2.0.3)
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
  • "In this post we will see how to use it in Xamarin.Forms **4.5.530** and up." – Jason Apr 10 '20 at 20:05
  • So... where that version then??????? – Eric Ouellet Apr 10 '20 at 20:41
  • 1
    I'm going to assume that's a typo and he means **4.5.0.530** - https://www.nuget.org/packages/Xamarin.Forms/4.5.0.530 – Jason Apr 10 '20 at 20:44
  • Updated to 4.5.0.617 and still the same problem...Weird ... – Eric Ouellet Apr 10 '20 at 21:13
  • 1
    it's in the release notes for that build - https://learn.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.5/4.5.0-sr4#embedded-fonts. It should be in the main Xamarin.Forms namespace - I assume you have `using Xamarin.Forms;` in the file? You might try the usual tricks of restarting VS, clearing bin/obj folders, etc – Jason Apr 10 '20 at 21:17
  • @Jason, that fix my problem... Can you write an answer? I forgot to add a using... Thanks a lot !!! – Eric Ouellet Apr 10 '20 at 21:29

1 Answers1

2

ExportFontAttribute is in the Xamarin.Forms namespace, so be sure you have

using Xamarin.Forms;
Jason
  • 86,222
  • 15
  • 131
  • 146