wpf中使用如下代码修改窗口的风格有许多局限性:不能统一修改所有控件的某一属性。
<Window.Resources>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="TextElement.FontFamily" Value="SimSun"/>
</Style>
</Window.Resources>
为解决此问题,可以用相关代码完成此功能。(.net 4.0)
public MainWindow()
{
InitializeComponent();
foreach (dynamic ctl in rootGrid.Children)
{
try
{
ctl.FontFamily = new FontFamily("SimSun");
}
catch { }
}
}
.net 3.0可以把ctl转换为FrameworkElement元素