如何改变WPF Datagrid.Column的cellStyle

时间:2017-01-13 08:24:58

标签: c# wpf

private void dataGrid_show_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)               
{
   if (dataGrid_show.Columns != null && (dataGrid_show.Columns.Count + 1) % 2 == 1)
   {
        e.Column.CellStyle = new Style(typeof(DataGridCell));
        e.Column.CellStyle.Setters.Add(new Setter(DataGridCell.BackgroundProperty,
                new SolidColorBrush(Colors.LightBlue)));
                e.Column.CellStyle.Setters.Add(
                    new Setter(DataGridCell.HorizontalAlignmentProperty, 
                               HorizontalAlignment.Left));
   ....
   }
}



private void dataGrid_show_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)               
{
   if (dataGrid_show.Columns != null && (dataGrid_show.Columns.Count + 1) % 2 == 1)
   {
        e.Column.CellStyle = new Style(typeof(DataGridCell));
        e.Column.CellStyle.Setters.Add(
                            new Setter(DataGridCell.BackgroundProperty,
                                       new SolidColorBrush(Colors.LightBlue)));
        e.Column.CellStyle.Setters.Add(
                            new Setter(DataGridCell.HorizontalAlignmentProperty, 
                                       HorizontalAlignment.Left));
    ....
   }
}

enter image description here

列线是这个,为什么?

0 个答案:

没有答案