开发者

Get font name from FontFamily in WPF

开发者 https://www.devze.com 2022-12-10 00:35 出处:网络
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'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

精彩评论

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