How to get a WPF DataGrid cell to right align without making the selectable area on a new row tiny?

后端 未结 5 1698
走了就别回头了
走了就别回头了 2021-01-31 13:38

I\'m using a WPF4.0 DataGrid. When double clicking on a cell in a new row everything works fine unless I\'ve added a cell style to that column. For example, I h

5条回答
  •  逝去的感伤
    2021-01-31 14:13

    I had the same issue and got it solved now. If you want to do it inside the c# code, you need to set a bunch of setters:

    DataGridTextColumn numColumn = new DataGridTextColumn
    Style s = new Style();
    s.Setters.Add(new Setter(HorizontalAlignmentProperty, HorizontalAlignment.Stretch));
    s.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Right));
    s.Setters.Add(new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Stretch));
    s.Setters.Add(new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Right));
    numColumn.CellStyle = s;
    

提交回复
热议问题