代码如下:
<Style x:Key="myGroup" TargetType="{x:Type GroupBox}">
<Setter Property="Header" Value="这里是标题"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<Grid VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Width="1000" Height="4" HorizontalAlignment="Left" Grid.Column="0">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.5" Color="Pink"/>
<GradientStop Offset="0" Color="#fff0f2"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<!--模板可变部分 GroupBox的header-->
<ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" Grid.Column="1" HorizontalAlignment="Center"></ContentPresenter>
<Rectangle Width="1000" Height="4" HorizontalAlignment="Right" Grid.Column="2">
<Rectangle.Fill>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.5" Color="Pink"/>
<GradientStop Offset="1" Color="#fff0f2"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
<Border CornerRadius="3" BorderThickness="1" BorderBrush="#cccccc" Margin="10,23,10,10"></Border>
<Border CornerRadius="3" BorderThickness="1" BorderBrush="#dddddd" Margin="13,26,13,13">
<!--模板可变部分 GroupBox的内容部分-->
<ContentPresenter Margin="4"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如图为自定义GroupBox样式。代码如下:&lt;Style x:Key="myGroup" TargetType="{x:Type GroupBox}"&gt; &lt;Setter Property="Header" Value="这里是标题"&gt;&lt;/Setter&gt; &lt;Setter Property=