Center the Header of the RadWindow

In order to allow the content in the header to be centered, you have to modify some elements in the ControlTemplate of the RadWindow. Before continuing you might want to take a look at the template structure of the RadWindow. You might also find useful to learn how to edit the default template of a control.

In the ControlTemplate for the RadWindow, find the Grid with name "Header". It should have a StackPanel placed in its first column:

XAML

<StackPanel Margin="2 0 0 0"
            Grid.Column="0"
            Orientation="Horizontal">
    <ContentPresenter x:Name="IconContent"
                      HorizontalAlignment="Left"
                      Margin="2"
                      VerticalAlignment="Center"
                      Content="{TemplateBinding Icon}"
                      ContentTemplate="{TemplateBinding IconTemplate}" />
    <ContentPresenter x:Name="HeaderContent"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"
                      Content="{TemplateBinding Header}"
                      ContentTemplate="{TemplateBinding HeaderTemplate}" />
</StackPanel>

Replace the StackPanel with a Grid, having two columns. Place the IconContent in the first column, then place the HeaderContent in the second one and set the HorizontalAlignment property of the ContentPresenter to Stretch.

XAML

<Grid Margin="2 0 0 0"
      Grid.Column="0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <ContentPresenter x:Name="IconContent"
                      Grid.Column="0"
                      HorizontalAlignment="Left"
                      Margin="2"
                      VerticalAlignment="Center"
                      Content="{TemplateBinding Icon}"
                      ContentTemplate="{TemplateBinding IconTemplate}" />
    <ContentPresenter x:Name="HeaderContent"
                      Grid.Column="1"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Center"
                      Content="{TemplateBinding Header}"
                      ContentTemplate="{TemplateBinding HeaderTemplate}" />
</Grid>

With this done, you can easily control the position of the content through the elements passed to the Header property:

C#

TextBlock textBlock = new TextBlock();
textBlock.Text = "My RadWindow";
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
RadWindow radWindow = new RadWindow();
radWindow.Width = 400;
radWindow.Height = 300;
radWindow.Style = this.Resources[ "RadWindowStyle" ] as Style;
radWindow.Header = textBlock;

VB.NET

Dim textBlock As New TextBlock()
textBlock.Text = "My RadWindow"
textBlock.HorizontalAlignment = HorizontalAlignment.Center
Dim radWindow As New RadWindow()
radWindow.Width = 400
radWindow.Height = 300
radWindow.Style = TryCast(Me.Resources("RadWindowStyle"), Style)
radWindow.Header = textBlock

Here is a snapshot of the final result:

See Also