Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
XamDataGrid horizontal content alignment issue

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



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?


Parents Reply Children
No Data