public FontFamilyDemoWindowViewModel() { var tempFontWeights = new Dictionary <string, FontWeight>(); var fontWeightProperties = typeof(System.Windows.FontWeights).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in fontWeightProperties) { tempFontWeights.Add(propertyInfo.Name, (FontWeight)propertyInfo.GetValue(null)); } FontWeights = tempFontWeights; SelectedFontWeight = FontWeights .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempFontStyles = new Dictionary <string, FontStyle>(); var fontStylesProperties = typeof(System.Windows.FontStyles).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in fontStylesProperties) { tempFontStyles.Add(propertyInfo.Name, (FontStyle)propertyInfo.GetValue(null)); } FontStyles = tempFontStyles; SelectedFontStyle = FontStyles .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempFontStretches = new Dictionary <string, FontStretch>(); var FontStretchsProperties = typeof(System.Windows.FontStretches).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in FontStretchsProperties) { tempFontStretches.Add(propertyInfo.Name, (FontStretch)propertyInfo.GetValue(null)); } FontStretches = tempFontStretches; SelectedFontStretch = FontStretches .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempSystemFontFamilies = new List <FontFamily>(); //增加自定义字体 var aileron = new FontFamily(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"FontFamilyDemo\FontFiles\#Aileron")); var aliFont = new FontFamily(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"FontFamilyDemo\FontFiles\#阿里巴巴普惠体 R")); tempSystemFontFamilies.Add(aileron); tempSystemFontFamilies.Add(aliFont); foreach (var systemFontFamily in Fonts.SystemFontFamilies) { tempSystemFontFamilies.Add(systemFontFamily); } SystemFontFamilies = tempSystemFontFamilies; }
public FontFamilyDemoWindowViewModel() { var tempFontWeights = new Dictionary <string, FontWeight>(); var fontWeightProperties = typeof(System.Windows.FontWeights).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in fontWeightProperties) { tempFontWeights.Add(propertyInfo.Name, (FontWeight)propertyInfo.GetValue(null)); } FontWeights = tempFontWeights; SelectedFontWeight = FontWeights .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempFontStyles = new Dictionary <string, FontStyle>(); var fontStylesProperties = typeof(System.Windows.FontStyles).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in fontStylesProperties) { tempFontStyles.Add(propertyInfo.Name, (FontStyle)propertyInfo.GetValue(null)); } FontStyles = tempFontStyles; SelectedFontStyle = FontStyles .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempFontStretches = new Dictionary <string, FontStretch>(); var FontStretchsProperties = typeof(System.Windows.FontStretches).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var propertyInfo in FontStretchsProperties) { tempFontStretches.Add(propertyInfo.Name, (FontStretch)propertyInfo.GetValue(null)); } FontStretches = tempFontStretches; SelectedFontStretch = FontStretches .FirstOrDefault(s => s.Key.Equals("Normal", StringComparison.OrdinalIgnoreCase)); var tempSystemFontFamilies = new List <FontFamily>(); foreach (var systemFontFamily in Fonts.SystemFontFamilies) { tempSystemFontFamilies.Add(systemFontFamily); } SystemFontFamilies = tempSystemFontFamilies; }