从代码背后的样式

时间:2012-07-09 19:39:43

标签: c# wpf xaml

我想从我的代码背后设置WPF数据网格,因为数据网格是在后面的代码中创建的。

我的应用程序中有一个包含所有样式的资源字典。

在XAML中,我将样式应用于数据网格,如下所示:

Style="{StaticResource DataGridStyle}"

如何在代码隐藏中创建的数据网格实现此目的,如下所示:

DataGrid dg = new DataGrid();

提前致谢。

1 个答案:

答案 0 :(得分:4)

dg.Style = this.Resources["DataGridStyle"] as Style;
相关问题