How to apply custom font icon shapes in UWP

Bharathi

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.

Martin Zikmund

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related