Bharathi
Bharathi

Reputation: 1328

How to apply custom font icon shapes in UWP

I want to show some custom shapes through font icons in my UWP project. I have created my own .ttf file for custom shapes. But I don't know how to apply it programmatically.

TextBlock text = new TextBlock();
string font = "Assets/mycustomfont.webfont.ttf#MyCustomFont";
text.FontFamily= new Windows.UI.Xaml.Media.FontFamily(font);                    
this.grid1.Children.Add(text);

Anyone please help me on this.

Upvotes: 1

Views: 955

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39082

The approach you are using is practically correct, but make sure to check the following:

  1. The .ttf file must be included in the project and have Build Action set to Content in the Properties window
  2. Start the path to the font with / to make sure it begins in root.
  3. Ensure the # suffix actually matches the font metadata. A font viewer app like dp4 Font Viewer can help you with that. Use the Font Family name as the suffix.

I have written an article on my blog about using custom fonts in UWP so check it out to see if you haven't missed some of the steps there.

Upvotes: 3

Related Questions