Get font name from FontFamily in WPF
Asked Answered
M

1

8

I'm currently working on a little font organization/preview application for myself, however, I'm having a hard time getting the exact information I need.

I've found that I can load an external font by just creating a new FontFamily object with the font's file location as its source. However, I can't find a way to get a font's specific font name back. I know I can use FontFamily.FamilyNames to get the font's family name back, but that's useless to me when I have multiple fonts with the same family being displayed. I'd like to actually display the specific name for the specific font.

Is there any way to do this? I currently display the file name instead, but it's incredibly sloppy because I have to iterate through every file in a directory and call Fonts.GetFontFamilies() on each just so I can get the actual file name(FontFamily's Source property only gives WPF's makeshift family-name source instead of something useful).

Manon answered 27/10, 2009 at 1:13 Comment(1)
FontFamily::GetTypefaces and then Typeface::FaceNames doesn't get you what you want?Wayworn
N
2

This is what I am doing:

        ListBoxItem listBoxItem = null;
        foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
        {
            listBoxItem = new ListBoxItem();
            listBoxItem.Content = fontFamily;
            listBoxItem.FontFamily=fontFamily; // Shows Font Text in the Font
            FontFamilyListBox.Items.Add(listBoxItem);
        }
Newspaperwoman answered 18/1, 2010 at 16:31 Comment(1)
So a simple ToString() on font family seems to work.Sitology

© 2022 - 2024 — McMap. All rights reserved.