wpf 一个好看的按钮样式(圆角按钮)

 1        <LinearGradientBrush x:Key="LinearGradientBlueBackground" EndPoint="0.5,1" StartPoint="0.5,0">
 2             <GradientStop Color="#FF377FED" Offset="0" />
 3             <GradientStop Color="#FF074CC0" Offset="1" />
 4         </LinearGradientBrush>
 5         <SolidColorBrush x:Key="MyBtnBorderColor" Color="#FF2D78F4"></SolidColorBrush>
 6         <SolidColorBrush x:Key="MyBtnHoverBackgroundColor" Color="#FF317EF3"></SolidColorBrush>
 7 
 8         <Style x:Key="FilletButton" TargetType="{x:Type Button}" >
 9             <Setter Property="Background" Value="{StaticResource LinearGradientBlueBackground}"></Setter>
10             <Setter Property="Foreground" Value="White"></Setter>
11             <Setter Property="BorderBrush" Value="{StaticResource MyBtnBorderColor}"></Setter>
12             <Setter Property="Template">
13                 <Setter.Value>
14                     <ControlTemplate TargetType="{x:Type Button}">
15                         <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" 
16                                 SnapsToDevicePixels="true" CornerRadius="6,6,6,6">
17                             <ContentPresenter x:Name="contentPresenter" 
18                                               Focusable="False" 
19                                               HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
20                                               Margin="{TemplateBinding Padding}" 
21                                               RecognizesAccessKey="True" 
22                                               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
23                                               VerticalAlignment="{TemplateBinding VerticalContentAlignment}"  />
24                         </Border>
25                         <ControlTemplate.Triggers>
26                             <Trigger Property="IsMouseOver" Value="true">
27                                 <Setter Property="Background" TargetName="border" Value="{StaticResource MyBtnHoverBackgroundColor}"/>
28                             </Trigger>
29                         </ControlTemplate.Triggers>
30                     </ControlTemplate>
31                 </Setter.Value>
32             </Setter>
33         </Style>
View Code

效果图如下:

感觉棒棒哒

猜你喜欢

转载自www.cnblogs.com/Lite/p/9075144.html
今日推荐