如何改变我的 Group-box 风格

How to change my Group-box style

所以这是我的 GroupBox:

<GroupBox 
    Header="My header"
    Background="Transparent"
    Foreground="Gainsboro"
    BorderBrush="Gainsboro" />

我有几件事想做 change/issues:

  1. Foreground虽然我已经改变了它,但它仍然是黑色的。
  2. 我的boderHeader周围:我想删除它以实现这种风格(headerborder之上):

  1. 所有header都是大写

编辑:

添加用户@mm8建议的style后,结果如下:

为什么我可以看到重复的边框?

创建您自己的一组控件以获得完全控制,类似于:

<Grid Width="100" Height="200" Background="DodgerBlue">
    <Grid.RowDefinitions>
        <RowDefinition Height="20"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Border BorderThickness="1" BorderBrush="Gainsboro">
        <TextBlock Foreground="Gainsboro">Header</TextBlock>
    </Border>

    <Border Grid.Row="1" BorderThickness="1" BorderBrush="Gainsboro">
        <!--Content-->
    </Border>
</Grid>

您可以覆盖 GroupBox 的模板:

<GroupBox Header="My header" Style="{x:Null}">
    <GroupBox.Template>
        <ControlTemplate TargetType="{x:Type 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 BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Grid.Column="0" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"/>
                <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="4" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3">
                    <Border.OpacityMask>
                        <MultiBinding ConverterParameter="7">
                            <MultiBinding.Converter>
                                <BorderGapMaskConverter />
                            </MultiBinding.Converter>
                            <Binding ElementName="Header" Path="ActualWidth"/>
                            <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
                        </MultiBinding>
                    </Border.OpacityMask>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
                        <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
                    </Border>
                </Border>
                <Border x:Name="Header" Grid.Column="1" Padding="3,1,3,0" Grid.Row="0" Grid.RowSpan="2" Background="LightGreen" BorderBrush="Black" CornerRadius="2" BorderThickness="1">
                    <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </Border>
                <ContentPresenter Grid.ColumnSpan="2" Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </Grid>
        </ControlTemplate>
    </GroupBox.Template>
    <TextBlock>content...</TextBlock>
</GroupBox>