我希望设置特定单元格的背景颜色 . 该行在后面的代码中被选中 . 虽然使用dataGrid的CurrentCell属性在后面的代码中选择了单元格,但IsSelected属性似乎不起作用 . 仅适用于表格 .
XAML:
<Style x:Key="CellStyle" TargetType="{x:Type dg:DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
码:
dg.CurrentCell = new DataGridCellInfo(dg.Items[0],dg.Columns[0]);
dg.CellStyle = this.FindResource("CellStyle") as Style;
2 回答
试试这个:
您可以在xaml中设置单元格样式:
然后:
尝试这个示例代码,它适用于我
NOTE
风格适用于所有细胞!
希望这可以帮助