using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Media; namespace FWindSoft.Wpf { /// /// wpf下字体相关命令 /// public class FontsUtil {//zh-cn public static List FontNames { get; private set; } static FontsUtil() { FontNames = GetAllFontNames(); //FontFamily不能加载我安装的字体,通过样式却可以 //try //{ // Awesome = new FontFamily(new Uri("pack://application:,,,/FWindSoft.Wpf;.component/Resources"), "FontAwesome"); //} //catch (Exception ex) //{ // throw; //} AwesomeKey= new ComponentResourceKey(typeof(FontsUtil), "FontAwesome"); } private static List GetAllFontNames() { List names=new List(); var collection = Fonts.SystemFontFamilies; foreach (var fontFamily in collection) { var tempFontName = fontFamily.FamilyNames; var chName = tempFontName.FirstOrDefault(c => c.Key.IetfLanguageTag == "zh-cn"); if (chName.Key == null) { chName = tempFontName.FirstOrDefault(); } if (chName.Key == null) continue; names.Add(chName.Value); } return names; } public static ResourceKey AwesomeKey { get; private set; } //public static FontFamily Awesome { get; set; } } }