Use Embedded resource font in AvalonEdit

14 views Asked by At

I am using AvalonEdit and want to set the font, at runtime, to use one I have added to the project and set the Build Action to Embedded Resource. But I cannot get the font to display, its always using the default font. Any suggestions what I'm doing wrong?

var newEditor = new TextEditor();
newEditor.SyntaxHighlighting = highlighter;

var customFont = new FontFamily(new Uri("pack://application:,,,/"), "./#pixels.ttf");

// Assign the custom font to AvalonEdit
newEditor.TextArea.FontFamily = customFont;
newEditor.FontFamily = customFont;
1

There are 1 answers

0
TheGrovesy On

Managed to fix this. The issue was that I needed to open the actual font file (in the Windows Font Inspector) and noted that the 'Font Name' was PIXELS, all caps, changed this in the code, and removed the file extension, and it worked.

Corrected line is:

var customFont = new FontFamily(new Uri("pack://application:,,,/"), "./#PIXELS");