以编程方式更改DataGridColumn边框粗细

时间:2017-03-06 09:57:57

标签: wpf wpfdatagrid code-behind

我正在寻找如何在代码隐藏中以编程方式更改DataGridColumn边框粗细或垂直网格线的示例?这可能吗?

1 个答案:

答案 0 :(得分:0)

您可以创建CellStyle来更改DataGrid的垂直网格线粗细:

dataGrid1.GridLinesVisibility = DataGridGridLinesVisibility.Horizontal;
Style cellStyle = new Style(typeof(DataGridCell));
cellStyle.Setters.Add(new Setter(DataGridCell.BorderThicknessProperty, new Thickness(0, 0, 5, 0)));
cellStyle.Setters.Add(new Setter(DataGridCell.BorderBrushProperty, Brushes.Black));
dataGrid1.CellStyle = cellStyle;

要更改水平边框粗细,您可以创建RowStyle

dataGrid1.GridLinesVisibility = DataGridGridLinesVisibility.Vertical;
Style rowStyle = new Style();
rowStyle.Setters.Add(new Setter(DataGridRow.BorderThicknessProperty, new Thickness(0, 0, 0, 5)));
rowStyle.Setters.Add(new Setter(DataGridRow.BorderBrushProperty, Brushes.Black));
dataGrid1.RowStyle = rowStyle;

这与MVVM无关。这是属于视图的基于视图的功能。