你必須在案件的Groupbox
覆蓋Template
要對齊頭Right
。默認情況下,它默認放置在默認模板中。
關鍵是
- 套裝
Grid.ColumnSpan
到2
邊境託管頭ContentPresenter。在ContentPresenter上設置HorizontalAlignment
到Right
。
這裏是一個將工作的XAML:
<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>
你必須編輯'GroupBox'的'ControlTemplate'作爲頭硬編碼留在那裏使用對齊'網格'和欄目安排。 –
http://stackoverflow.com/questions/2104013/wpf-groupbox-header-postion-alignment – har07