Hi all,
I am trying to align the text of my columns dynamically so that means I cannot do anything in the xaml. I am using this piece of code that I found:
void datagrid_FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) {
{
for (int i = 0; i < e.FieldLayout.Fields.Count; i++) {
Style myStyle = new Style(typeof(CellValuePresenter
)); myStyle.Setters.Add(
myStyle.Setters.Add(
new Setter(CellValuePresenter.HorizontalContentAlignmentProperty, HorizontalAlignment.Center ));
e.FieldLayout.Fields[i].Settings.CellValuePresenterStyle = myStyle;
} }
}
The problem is that the content itself is not aligned in the center. Number fields are aligned to the right and text fields to the left. What happens is when I click on a cell, the textbox to input the data is centered. Once I click out of the cell, it goes back to being aligned the way before. I need the data, both number and text fields, to be aligned center.
Any suggestions?