创建新样式
/// <summary>
/// 创建新样式
/// </summary>
/// <param name="type">控件类型</param>
/// <param name="style">基础样式</param>
/// <param name="family">字体名称</param>
/// <returns></returns>
Style CreateStyle(Type type, Style style, FontFamily family)
{
var rslt = new Style(type, style);
rslt.Setters.Add(new Setter(FontFamilyProperty, family));
rslt.Setters.Add(new Setter(FontSizeProperty, (double)24));
return rslt;
}
获取系统所有字体
var fonts = new InstalledFontCollection();
var rslt = fonts.Families.Select(s => s.Name).ToList();
var family = new FontFamily(rslt[0]);
gridTest.Style = CreateStyle(gridTest.GetType(), gridTest.Style, family);