Frage

I'am using Font Awesome in my Windows Phone 8 App. I have added a part of the unicode in the database (for example f000). In my code I add "\u" to complete the unicode. I add it like this:

_model.ContentImage = @"\u" + rec.UniContentImage;

When I'm debugging it and add a breakpoint, the contentimage is filled with "\\uf000"(in debugger). And the font will not be displayed. When I'am changing the content in contentimage(in debugger) to "\uf000" awesome font is displayed correctly.

Does anyone know how I can add font awesome correctly and dynamically in c#?

War es hilfreich?

Lösung

This will load the FontAwesome custom font for use in Windows 8.1 Universal apps:

FontFamily customFont = new FontFamily("ms-appx:///Assets/FontAwesome.otf#FontAwesome");
textBlock.FontFamily = customFont;
textBlock.Text = "\uf164"; // thumbs up!

NB: Set the 'FontAwesome.otf' Properties:

  • Build Action: 'Content'
  • Copy to Output Directory: 'Do not copy'

Also here is the Data model method I use to return Unicode string for Binding (where this.code is "\uf164"):

public String unicode
    {
        get
        {
            String codePoint = this.code.Substring(2); // remove '\u' => "f164";
            int unicode = int.Parse(codePoint, System.Globalization.NumberStyles.HexNumber);
            String unicodeString = char.ConvertFromUtf32(unicode).ToString();
            return unicodeString; // "\uf164"
        }
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top