Reputation: 1328
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
Reputation: 39082
The approach you are using is practically correct, but make sure to check the following:
.ttf
file must be included in the project and have Build Action set to Content in the Properties window/
to make sure it begins in root.#
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