I am using a xamGrid in my SL4 app. I am manually creating some columns, not using XAML. At the time that i am constructing the column I am setting HeaderTextHorizontalAlignment = HorizontalAlignment.Center yet I am not seeing the column header centered. What am I doing wrong?
Hello stevendm,
According to the sample that you have attached you would like to have Customer and No , No under Customer and both to be centered. HeaderTextHorizontalAlignment aligns it to the center but in your case it is better to use HeaderTemplate of a column . You could do it in Xaml or in code behind very easy :
TextColumn c2 = new TextColumn { Key = "CustomerNumber", HeaderTemplate = template, HorizontalContentAlignment = HorizontalAlignment.Center, HeaderTextHorizontalAlignment = HorizontalAlignment.Center }; myGrid.Columns.Add(c2);
where template object is from type DataTemplate , where
DataTemplate template = Create(); public DataTemplate Create() { return (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"" > <StackPanel Orientation=""Vertical""> <TextBlock TextAlignment=""Center"" > Customer </TextBlock> <TextBlock TextAlignment=""Center"" > No </TextBlock> </StackPanel> </DataTemplate>"); } Hope that helps , Nikola .
DataTemplate template = Create();
public DataTemplate Create() { return (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"" > <StackPanel Orientation=""Vertical""> <TextBlock TextAlignment=""Center"" > Customer </TextBlock> <TextBlock TextAlignment=""Center"" > No </TextBlock> </StackPanel> </DataTemplate>"); } Hope that helps , Nikola .
public DataTemplate Create() { return (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"" > <StackPanel Orientation=""Vertical""> <TextBlock TextAlignment=""Center"" > Customer </TextBlock> <TextBlock TextAlignment=""Center"" > No </TextBlock> </StackPanel> </DataTemplate>"); }
Hope that helps , Nikola .
First of all thank you for using the forum to share that problem that you are having. I tried to reproduce your issue with the code snippets that you gave , but i couldn't ! Would you please give a sample , where that problem is reproducible and also the version that you are using - for example 10.2.20102.XXXX or 10.3.20103.XXXX. I am waiting for you answer !
Regards , Nikola.
I have also set the following style the app.xaml file and I can see it turn red but it is still left justified
<Style x:Key="HeaderStyle" TargetType="igPrim:HeaderCellControl"> <Setter Property="Foreground" Value="Red" /> <Setter Property="HorizontalAlignment" Value="Stretch"></Setter> <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> </Style>
Here is the exact code TextColumn c2 = new TextColumn { Key = "CustomerNumber", HeaderText = "Customer\nNo.", HorizontalContentAlignment = HorizontalAlignment.Center, HeaderTextHorizontalAlignment = HorizontalAlignment.Center }; _orderConfigurationGrid.Columns.Add(c2);