Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改WPF Datagrid.Column的cellStyle_C#_Wpf - Fatal编程技术网

C# 如何更改WPF Datagrid.Column的cellStyle

C# 如何更改WPF Datagrid.Column的cellStyle,c#,wpf,C#,Wpf,列线是这样的,为什么?此行为是由于将水平对齐设置为左引起的。,使单元格填充可用空间。要对齐文本请改用HorizontalContentAlignment,但由于Left是此处的默认值,因此您根本不需要设置任何对齐方式……非常感谢!我使用了中心样式,但什么也没有发生,代码如下:e.Column.CellStyle.Setters.Add(newsetter(DataGridCell.HorizontalContentAlignmentProperty,horizontallignment.cent


列线是这样的,为什么?

此行为是由于将
水平对齐设置为
引起的。,使单元格填充可用空间。要对齐
文本
请改用
HorizontalContentAlignment
,但由于
Left
是此处的默认值,因此您根本不需要设置任何对齐方式……非常感谢!我使用了中心样式,但什么也没有发生,代码如下:e.Column.CellStyle.Setters.Add(newsetter(DataGridCell.HorizontalContentAlignmentProperty,horizontallignment.center));
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));
    ....
   }
}