我以这种方式编写了以编程方式添加列的DataGrid:
var column = new DataGridCheckBoxColumn
{
Header = _info.GetProcessingUnit(j).Code,
Binding = new Binding("Coef" + j)
};
var styleCellItem = new System.Windows.Style(typeof (DataGridCell));
styleCellItem.Setters.Add(new System.Windows.Setter
{
Property = DataGridCell.BackgroundProperty,
Value = new Binding("AssignedColor" + j),
});
column.CellStyle = styleCellItem;
dg.Columns.Add(column);
我还需要添加这样的风格:
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsEditing" Value="True" />
</Trigger>
</Style.Triggers>
可能应该从这样的事情开始:
styleCellItem.Triggers.Add(new System.Windows.Trigger
但我不知道如何写它。