gpt4 book ai didi

c# - 从代码背后设计样式

转载 作者:行者123 更新时间:2023-11-30 21:06:02 25 4
gpt4 key购买 nike

我想从我的代码隐藏中设置 WPF 数据网格的样式,因为数据网格是在代码隐藏中创建的。

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

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

Style="{StaticResource DataGridStyle}"

对于在代码隐藏中创建的数据网格,我如何实现这一点,如下所示:

DataGrid dg = new DataGrid();

提前致谢。

最佳答案

dg.Style = this.Resources["DataGridStyle"] as Style;

关于c# - 从代码背后设计样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11401947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com