You have to override Template
of Groupbox
in case you want to align header to Right
. By default it is placed at left in default template.
Key is to
- Set
Grid.ColumnSpan
to 2
on border hosting Header ContentPresenter.
- Set
HorizontalAlignment
to Right
on ContentPresenter.
Here is the XAML which will work:
<GroupBox Header="abc">
<GroupBox.Template>
<ControlTemplate TargetType="GroupBox">
<Grid SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="6" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="6" />
</Grid.RowDefinitions>
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
CornerRadius="4,4,4,4"
BorderBrush="#00FFFFFF"
Background="{TemplateBinding Panel.Background}"
Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3" />
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
CornerRadius="4,4,4,4"
BorderBrush="#FFFFFFFF"
OpacityMask="{x:Null}"
Grid.Row="1"
Grid.ColumnSpan="4"
Grid.RowSpan="3">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
CornerRadius="3,3,3,3"
BorderBrush="{TemplateBinding Border.BorderBrush}">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
CornerRadius="2,2,2,2"
BorderBrush="#FFFFFFFF" />
</Border>
</Border>
<Border Padding="3,1,3,0"
Name="Header"
Grid.Column="1"
Grid.ColumnSpan="2" <-- HERE
Grid.Row="0"
Grid.RowSpan="2">
<ContentPresenter RecognizesAccessKey="True"
HorizontalAlignment="Right" <-- And HERE
Content="{TemplateBinding HeaderedContentControl.Header}"
ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
ContentStringFormat="{TemplateBinding HeaderedContentControl.HeaderStringFormat}"
ContentSource="Header"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
Margin="{TemplateBinding Control.Padding}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
Grid.Column="1"
Grid.Row="2"
Grid.ColumnSpan="2" />
</Grid>
</ControlTemplate>
</GroupBox.Template>
</GroupBox>