开发者

Get font name from FontFamily in WPF

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 nam开发者_JAVA技巧e 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).


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);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜