{"id":9410,"date":"2022-08-13T10:53:19","date_gmt":"2022-08-13T10:53:19","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9410"},"modified":"2022-08-13T10:53:19","modified_gmt":"2022-08-13T10:53:19","slug":"adding-fonts-the-a-maui-application","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/adding-fonts-the-a-maui-application\/","title":{"rendered":"Adding fonts the a MAUI application"},"content":{"rendered":"<p>When you create a MAUI application, the default application&#8217;s MauiProgram.cs contains the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nbuilder\r\n  .UseMauiApp&lt;App&gt;()\r\n  .ConfigureFonts(fonts =&gt;\r\n  {\r\n    fonts.AddFont(&quot;OpenSans-Regular.ttf&quot;, &quot;OpenSansRegular&quot;);\r\n    fonts.AddFont(&quot;OpenSans-Semibold.ttf&quot;, &quot;OpenSansSemibold&quot;);\r\n  });\r\n<\/pre>\n<p>As can be seen, we&#8217;re using <em>.AddFont<\/em> to add .ttf filename along with an optional alias.<\/p>\n<p>The .ttf files are stored in the Resources\/Fonts folder or our application&#8217;s project and ofcourse the file name&#8217;s match those used in <em>.AddFont<\/em><\/p>\n<p>To use our font&#8217;s within the MAUI XAML we simply use the alias name like this<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;Setter Property=&quot;FontFamily&quot; Value=&quot;OpenSansRegular&quot;\/&gt;\r\n<\/pre>\n<p><em>This is taken from the default MAUI application&#8217;s Styles.xaml file.<\/em><\/p>\n<p><strong>Adding our own font<\/strong><\/p>\n<p>This all looks fairly simple, so let&#8217;s add a font from <a href=\"https:\/\/fonts.google.com\/\" rel=\"noopener\" target=\"_blank\">Google Fonts<\/a>.<\/p>\n<p>I&#8217;m going to download the DynaPuff font, as I want something that will stand out when its changed.<\/p>\n<ul>\n<li>Download your font choice<\/li>\n<li>From the zip I opened static\\DynaPuff and copied DynaPuff-Regular.ttf into my application&#8217;s Resources\/Fonts folder<\/li>\n<li>Within MauiProgram.cs I added the following to the ConfigureFonts method\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nfonts.AddFont(&quot;DynaPuff-Regular.ttf&quot;, &quot;DynaPuff&quot;);\r\n<\/pre>\n<\/li>\n<li>To test this, I changed a XAML Label element (the Hello, World label in the default generated application) to add this\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nFontFamily=&quot;DynaPuff&quot;\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>And that&#8217;s it, really simple. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you create a MAUI application, the default application&#8217;s MauiProgram.cs contains the following builder .UseMauiApp&lt;App&gt;() .ConfigureFonts(fonts =&gt; { fonts.AddFont(&quot;OpenSans-Regular.ttf&quot;, &quot;OpenSansRegular&quot;); fonts.AddFont(&quot;OpenSans-Semibold.ttf&quot;, &quot;OpenSansSemibold&quot;); }); As can be seen, we&#8217;re using .AddFont to add .ttf filename along with an optional alias. The .ttf files are stored in the Resources\/Fonts folder or our application&#8217;s project and ofcourse the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[330],"tags":[],"class_list":["post-9410","post","type-post","status-publish","format-standard","hentry","category-maui"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9410"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9410\/revisions"}],"predecessor-version":[{"id":9412,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9410\/revisions\/9412"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}