如何将单元格样式应用于DataGrid单元格
我有以下DataGrid
我有以下单元格样式来更改选定的Backcolor
我已尝试应用CellStyle="{StaticResource DataGridCell}"
如上所示,并使用DynamicResource
但资源无法解析。 我已经导入了正确的资源字典,因为其他样式正在工作我在这里做错了什么?
谢谢你的时间。
由于您的Style
没有Key
您不必在DataGrid
上设置CellStyle
,默认情况下它将应用于所有DataGridCell
。
如果您不希望它应用于所有DataGridCell
默认情况下将样式赋予x:Key
并在DataGrid
上设置CellStyle
例:
要将样式仅应用于某些DataGridRow:
创建DataGridCell样式:
< !-- DataGridCell Style--> < Style x:Key="MyDataGridCellStyle" TargetType="{x:Type DataGridCell}">
在您想要的列中使用它
< !-- DataGrid -->