相关文章推荐

1、模板改写XAML

<Style  TargetType="{x:Type GroupBox}" x:Key="Group">
    <Setter Property="Margin" Value="5"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupBox}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Border x:Name="border" Grid.Row="0" SnapsToDevicePixels="True" BorderBrush="{TemplateBinding Background}" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" BorderThickness="0"  CornerRadius="2,2,0,0" >
                        <Grid Margin="5">
                            <ContentPresenter Name="header" Visibility="Collapsed" ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                            <TextBlock FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}" Text="{Binding ElementName=header, Path=Content}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                        </Grid>
                    </Border>
                    <Border Grid.Row="1" BorderBrush="{TemplateBinding Background}" SnapsToDevicePixels="True" BorderThickness="1,0,1,1" CornerRadius="0,0,2,2" >
                        <ContentPresenter Margin="10" x:Name="cpmdi" />
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="Header" Value="{x:Null}">
                        <Setter TargetName="cpmdi" Property="Margin" Value="10"/>
                        <Setter TargetName="border" Property="Height" Value="32"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

2、引用示例代码

<GroupBox Margin="20" Header="GroupBox自定义示例" FontSize="15" HorizontalAlignment="Left" Foreground="Red" Style="{StaticResource Group}" Background="Teal">
    <StackPanel >
        <Button Margin="0,5" Height="30" Content="测试1"/>
        <TextBox Text="测试3"/>
    </StackPanel>
</GroupBox>

3、效果图

1、模板改写XAML&amp;lt;Style TargetType=&quot;{x:Type GroupBox}&quot; x:Key=&quot;Group&quot;&amp;gt; &amp;lt;Setter Property=&quot;Margin&quot; Value=&quot;5&quot;/&amp;gt; &amp;lt;Setter Property=&quot;Template&quot;&amp;gt; &amp;lt;Setter
WPF之 Group Box 样式 _边框透明XAML: Group Box 引用:效果:使用前:使用后: XAML: <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/> <Style x:Key=" Group box WithoutBorder" TargetType="{x:Type Group Box }"> <Setter Property="BorderBrush" Value="#D5D
带标题的文本控件带标题的文本控件, Group Box \Expander\ItemControl,共同点是: 1.有标题Header 2.有文本,可以更复杂,在布局控件内更多元素来表达文本 Group Box Group Box 简单示例,没有特殊的属性 < Group Box Header="This is a Group Box " HorizontalAlignment="Left" Margin="36,
 
推荐文章