This is a migrated thread and some comments may be shown as answers.

Cannot define global style for HeaderTextAlignment

1 Answer 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cezar
Top achievements
Rank 1
Cezar asked on 29 Jul 2011, 11:42 PM

Hello Telerik,

Here is the style:

<Window.Resources>
        <Style TargetType="telerik:GridViewColumn">
           <Setter Property="HeaderTextAlignment" Value="Center"/>
      </Style>
 </Window.Resources>

And here is the grid:

<telerik:RadGridView Name="radGridScenario" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserFreezeColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False" AutoGenerateColumns="False" >
   
     <telerik:RadGridView.Columns>
     <telerik:GridViewDataColumn DataMemberBinding="{Binding BusName}" UniqueName="BusName" Header="Bus Name" Width="100" />
    </telerik:RadGridView.Columns>

</telerik:RadGridView>

Observe the style is not working and the column is left centered (default behaviour). To make it working I have to create a named style and assign this style by key to every column. Why can't I create a global default style for all the columns automatically?
Just in case somebody wants to point out that I should create style for GridViewDataColumn (instead of GridViewColumn) my answer is that GridViewDataColumn is derived from GridViewColumn and even if I do that in the style definition it's stil not working.

If I apply the same technique to other grid properties, for example to center check box then it is working.

Thanks,
Cezar

 

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 30 Jul 2011, 08:06 AM
Hi Cezar,

 
The behavior you get is the expected one. Since columns are not visual objects you cannot create a style targeted at a column. You may set the HeaderTextAlignment property to each column. If your headers are strings you may create a style targeted at a TextBlock element and set its HorizontalAlignment from there.

 

Best wishes,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
GridView
Asked by
Cezar
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or