Search code examples
c#windows-store-appscustom-font

Custom font in code behind - Windows Store Apps


I have an issue with setting custom font from code behind in Windows Store Apps (Windows 8.1, C#).

It is working in XAML, but not in code behind. I have added my font *.ttf file to Assets. Set Build Action = Content. I have set path to my font file like this:

<TextBlock Text="&#xe1de;" FontFamily="ms-appx:///Assets/My-icons.ttf#My-icons"/>

It's working (displaying my icon), when I set text property in XAML, but as soon as I set text to this TextBlock in code behind or create new TextBlock with the same properties in code behind - it's not working (displaying unicode).

Can anyone help me with this?


Solution

  • Does this help:

    char ch = (char)0xF8FF;
    YourTextBlock.Text = ch.ToString();