xamarin.formsurhosharp

How do I load a custom Font in Xamarin using UrhoSharp?


I am trying to follow the example posted by Adam Pedley at Introduction to UrhoSharp in Xamarin Forms but have run into a problem. In the following code block, he is loading a custom font:

private void CreateText()
{
    // Create Text Element
    var text = new Text()
    {
        Value = "Hello World!",
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center
    };

    text.SetColor(Color.Cyan);
    text.SetFont(font: ResourceCache.GetFont("Fonts/Anonymous Pro.ttf"), size: 30);
    // Add to UI Root
    UI.Root.AddChild(text);
}

The problem I have is that I don't have this font, and it isn't included anywhere in any kind of Assets folder or anything in his GitHub repository of his demo project at adamped/UrhoSharp.Demo. In fact, in spite of the allusion to a "Fonts" folder in the function call, no Fonts folder exists in his demo solution in any of the projects.

Trying to run the application results in a mono runtime error " [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Could not find resource...".

In addition, there doesn't seem to be any means of contacting the author to ask (which I find doubly frustrating), so I am having to ask the Stack Overflow community: Where and how do I place custom font assets in my solution (his solution) so that a custom font may be used?

I am currently able to use a custom font in a standard Label with the font file being located in the /Assets folder of both my Sample.Android and Sample.UWP projects, but no combination of path or file name I have tried in the call to GetFont(...) works.


Solution

  • After hours of searching, I finally came across a screen shot showing the proper setup for anyone else who may run into this issue;

    Image of solution to problem