How to center or right align the Header in the WPF RadGridView by Telerik?

Telerik is not the best at providing documentation on how to do things, so I figured I would write some of the more mundane tasks that took me a few minutes thought.

Here, I needed to center my headers. It is easy but only if you know all the magic words. If you don’t, it is pretty hard.

Here is how you do it. A simple style.

Snippet

        <telerik:RadTreeListView ItemsSource="{Binding Nodes}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                               IsExpandedBinding="{Binding IsExpanded,Mode=TwoWay}"                                 
                               Name="mainTree"
                               SelectionUnit="FullRow"                                 
                               RowIndicatorVisibility="Collapsed"
                               CanUserResizeColumns="False"
                             SelectedItem="{Binding SelectedNode,Mode=TwoWay}"
                               >
            <telerik:RadTreeListView.Resources>
                <Style BasedOn="{StaticResource {x:Type telerik:GridViewHeaderCell}}" TargetType="{x:Type  telerik:GridViewHeaderCell}">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                </Style>
            </telerik:RadTreeListView.Resources>
......

Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *