我想在 WPF Datagrid 中設定特定列的所有單元格的背景顏色。
要求非常簡單明了,但我對 WPF 很陌生。
我發現了數百個類似Style Only One Column's Cells DataGrid C# WPF的帖子,它們使用DataGridCell和DataTrigger組合來設定特定單元格的樣式,但觸發器始終依賴于該單元格上的資料,而我不想依賴于資料但只是列索引。
有沒有辦法做到這一點?
uj5u.com熱心網友回復:
您可以使用一個簡單的樣式和一個背景設定器(每列的單獨樣式):
<DataGridTextColumn Binding="{Binding ...}" Header="Red">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Red"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ...}" Header="Green">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Green"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ...}" Header="Blue">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Blue"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486020.html
