将单元格的内容对齐到中心

时间:2015-11-02 16:47:40

标签: wpf wpf-controls wpfdatagrid

Datagrid单元格的内容需要居中。设置textalignment属性。 但内容不集中。我错过了什么。

        Style aStyle = new Style()
        {
          TargetType = typeof(TextBlock)

         };

           aStyle.Setters.Add(new Setter(TextBlock.TextAlignmentProperty,TextAlignment.Center));

        DataGridTextColumn c1 = new DataGridTextColumn();
        c1.Width = 20;
        c1.Header = "Index";
        c1.Binding = new Binding("Index");
        c1.Width = 110;
        c1.IsReadOnly = true;
        c1.ElementStyle = aStyle;
        aDataGrid.Columns.Add(c1);

0 个答案:

没有答案