WPF GroupBox 样式分享

原文:WPF GroupBox 样式分享

默认样式

WPF GroupBox 样式分享GroupBox 样式分享" title="WPF GroupBox 样式分享">

添加样式后



WPF GroupBox 样式分享GroupBox 样式分享" title="WPF GroupBox 样式分享">

样式代码:

<Style TargetType="{x:Type
GroupBox}">

           
<Setter Property="BorderBrush"
Value="#D5DFE5"/>

           
<Setter Property="BorderThickness"
Value="1"/>

           
<Setter Property="Template">

               
<Setter.Value>

                   
<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"
MinHeight="59"/>

                               
<RowDefinition Height="*"/>

                               
<RowDefinition Height="6"/>

                           
</Grid.RowDefinitions>

                           
<Border BorderBrush="Transparent"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.ColumnSpan="4" Grid.Column="0" CornerRadius="4" Grid.Row="0"
Grid.RowSpan="4" Background="#FFE5E5E5"
Margin="0,-0.25,0,0.25">

                               
<Border.Effect>

                                   
<DropShadowEffect Color="#FFAAAAAA"
Direction="350"/>

                               
</Border.Effect>

                           
</Border>

                           
<Border x:Name="Header" Grid.Column="1"
Padding="3,1,3,0" Grid.Row="1" Grid.RowSpan="1"
HorizontalAlignment="Right" Background="{x:Null}" Margin="0"
Height="16.96" VerticalAlignment="Top"/>

                           
<ContentPresenter Grid.ColumnSpan="2"
Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="2"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Grid.RowSpan="1"/>

                           
<Border BorderBrush="White"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.ColumnSpan="4" CornerRadius="4" Grid.Row="1"
Grid.RowSpan="3">

                               
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="3">

                                   
<Border BorderBrush="White"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="2"/>

                               
</Border>

                           
</Border>

                           
<Grid x:Name="HeaderGrid" Height="47.2"
VerticalAlignment="Stretch" Grid.Column="2" Grid.ColumnSpan="2"
Grid.RowSpan="1" Margin="0,7.982,-16,3.818" Grid.Row="1"
HorizontalAlignment="Right">

                               
<Path Data="M12.19,0 L12.290733,14.847
-1.3000648E-08,14.847 z" Height="16.1" Margin="0,0,8.067,0"
RenderTransformOrigin="0.499999978361064,0.499999995889058"
Stretch="Fill" Stroke="Black" StrokeThickness="0"
VerticalAlignment="Top" HorizontalAlignment="Right" Width="12.29"
>

                                   
<Path.Fill>

                                       
<LinearGradientBrush EndPoint="0.466,2.201"
StartPoint="0.5,0">

                                           
<GradientStop Color="#C66A6A6A"
Offset="1"/>

                                           
<GradientStop Color="#E1434343"
Offset="0.855"/>

                                           
<GradientStop Color="#FFC6C6C6"
Offset="0.11"/>

                                       
</LinearGradientBrush>

                                   
</Path.Fill>

                                   
<Path.RenderTransform>

                                       
<TransformGroup>

                                           
<ScaleTransform/>

                                           
<SkewTransform/>

                                           
<RotateTransform
Angle="90.087"/>

                                           
<TranslateTransform Y="-6.04399277075815"
X="6.0531771644038841"/>

                                       
</TransformGroup>

                                   
</Path.RenderTransform>

                               
</Path>

                               
<Border BorderBrush="Black" BorderThickness="0"
Margin="0,8.061,0,0" CornerRadius="16,0,0,16"
Background="White">

                                   
<Border.Effect>

                                       
<DropShadowEffect Direction="195" BlurRadius="10"
Opacity="0.305" ShadowDepth="6"/>

                                   
</Border.Effect>

                                   
<Border x:Name="contentBorder" BorderBrush="Black"
Margin="6,6,0,6" CornerRadius="16,0,0,16">

                                       
<Border.Background>

                                           
<LinearGradientBrush EndPoint="1.002,0.498"
StartPoint="-0.024,0.502">

                                               
<GradientStop Color="#FF678B03"
Offset="0.027"/>

                                               
<GradientStop Color="#FFA4C43D"
Offset="0.948"/>

                                               
<GradientStop Color="#FFADCA54"
Offset="0.969"/>

                                               
<GradientStop Color="#FFA7C646"
Offset="0.975"/>

                                               
<GradientStop Color="#FFC9EF4C"
Offset="0.994"/>

                                           
</LinearGradientBrush>

                                       
</Border.Background>

                                       
<Grid>

                                           
<ContentControl HorizontalAlignment="Left"
Margin="20,0,23,0" VerticalAlignment="Center"
Foreground="White">

                                               
<ContentPresenter ContentSource="Header"
RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding
SnapsToDevicePixels}" HorizontalAlignment="Stretch"
VerticalAlignment="Center" Margin="0"
Width="212.323"/>

                                           
</ContentControl>

                                       
</Grid>

                                   
</Border>

                               
</Border>

                           
</Grid>

                       
</Grid>

                   
</ControlTemplate>

               
</Setter.Value>

           
</Setter>

       
</Style>

前台布局:

<Grid
x:Name="bootGrid">

       
<GroupBox Header="groupBox1" 
x:Name="groupBox1" Margin="100" MinHeight="200"
MinWidth="200">

           
<Grid>

               
<Grid.ColumnDefinitions>

                   
<ColumnDefinition Width="75"/>

                   
<ColumnDefinition Width="10"/>

                   
<ColumnDefinition
Width="150*"/>

               
</Grid.ColumnDefinitions>

               
<Grid.RowDefinitions>

                   
<RowDefinition Height="28"/>

                   
<RowDefinition Height="28"/>

                   
<RowDefinition Height="28"/>

                   
<RowDefinition/>

               
</Grid.RowDefinitions>

               
<TextBlock HorizontalAlignment="Right"
TextWrapping="Wrap" Text="Name:"
VerticalAlignment="Center"/>

               
<TextBlock HorizontalAlignment="Right"
TextWrapping="Wrap" Text="Phone:" VerticalAlignment="Center"
Margin="0" Grid.Row="1"/>

               
<TextBlock HorizontalAlignment="Right"
TextWrapping="Wrap" Text="Email:" VerticalAlignment="Center"
Margin="0" Grid.Row="2"/>

               
<TextBlock HorizontalAlignment="Right"
TextWrapping="Wrap" Text="Address:" VerticalAlignment="Top"
Margin="0 10 0 0" Grid.Row="3"/>

<TextBox Margin="0,0,18.241,0" TextWrapping="Wrap"
VerticalAlignment="Center" Grid.Column="2"
Height="24"/>

               
<TextBox Margin="0,0,18.241,0" TextWrapping="Wrap"
VerticalAlignment="Center" Grid.Column="2" Height="24"
Grid.Row="1"/>

               
<TextBox Margin="0,0,18.241,0" TextWrapping="Wrap"
VerticalAlignment="Center" Grid.Column="2" Height="24"
Grid.Row="2"/>

               
<TextBox Margin="0,2,18.241,20" TextWrapping="Wrap"
VerticalAlignment="Stretch"  Grid.Column="2"
MinHeight="58" Grid.Row="3"/>

           
</Grid>

       
</GroupBox>

   
</Grid>

上一篇:iOS手机应用开发原型模板及开发流程


下一篇:【LOJ】#2131. 「NOI2015」寿司晚宴