从背后的代码样式 [英] Styling from code behind
本文介绍了从背后的代码样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从背后的代码中设置 WPF 数据网格的样式,因为数据网格是在背后的代码中创建的.
I would like to style a WPF data-grid from my code behind, as the data-grid is created in code behind.
我的应用程序中有一个包含所有样式的资源字典.
I have a resource dictionary in my application with all styles.
在 XAML 中,我会将样式应用到数据网格,如下所示:
In XAML I would apply the style to the data-grid as follows:
Style="{StaticResource DataGridStyle}"
如何为在代码后面创建的数据网格实现这一点,如下所示:
How can I achieve this for a data-grid created in code behind as follows:
DataGrid dg = new DataGrid();
提前致谢.
推荐答案
dg.Style = this.Resources["DataGridStyle"] as Style;
这篇关于从背后的代码样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文