How can I center the Silverlight DataGridTemplateColumn header?
I want to center a title on a Silverlight DataGridTemplateColumn. The following code will get me most of the way:
DataGridTemplateColumn column = new DataGridTemplateColumn();
column.CellTemplate = Resources[templateName] as DataTemplate;
column.Header = headerName;
column.HeaderStyle = new Style { TargetType = typeof(DataGridColumnHeader) };
column.HeaderStyle.Setters.Add(new Setter(DataGridColumnHeader.HorizontalAlignmentProperty, HorizontalAlignment.Center));
The heading is indeed centered, but if the column is expanded the heading is not stretched. It just stays the original width, leaving white gaps on either side of it, which looks terrible.
What is the correct way to center the column header so that it still takes up the full width?
+2
a source to share