Text alignment in a WPF DataGrid

后端 未结 13 735
野性不改
野性不改 2020-12-14 14:13

How can I align the column data to center in a WPF DataGrid?

相关标签:
13条回答
  • 2020-12-14 14:44

    Here's @MohammedAFadil's XAML answer, converted to C# code behind:

    var MyStyle = new Style(typeof(DataGridCell)) {
        Setters = {
            new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center)
        }
    };
    

    To apply the Style, set the CellStyle property of the DataGrid, e.g.

    var MyGrid = new DataGrid() {
        CellStyle = MyStyle
    };
    
    0 讨论(0)
提交回复
热议问题