WPF圆角按钮
右下角那个是按钮选中时的状态。
这个按钮制作是重写按钮的Template样式,改变圆角,只需要改变Template里面Border中CornerRadius的四个值。
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
< Button Content = "地图" Height = "50" Margin = "555,282,466,393" Width = "50" >
< Button.Template >
< ControlTemplate TargetType = "{x:Type Button}" >
< Border BorderBrush = "{TemplateBinding Control.BorderBrush}" BorderThickness = "0" CornerRadius = "3,13,3,13" Name = "PART_Background" >
< Border.Background >
< LinearGradientBrush EndPoint = "0,1" StartPoint = "0,0" >
< GradientStop Color = "White" Offset = "0.0" />
< GradientStop Color = "Silver" Offset = "0.5" />
< GradientStop Color = "White" Offset = "0.0" />
</ LinearGradientBrush >
</ Border.Background >
< ContentPresenter Content = "{TemplateBinding ContentControl.Content}" HorizontalAlignment = "Center" VerticalAlignment = "Center" />
</ Border >
< ControlTemplate.Triggers >
< Trigger Property = "UIElement.IsMouseOver" Value = "True" >
< Setter Property = "Border.Background" TargetName = "PART_Background" >
< Setter.Value >
< LinearGradientBrush EndPoint = "0,1" StartPoint = "0,0" >
< GradientStop Color = "Silver" Offset = "0.0" />
< GradientStop Color = "White" Offset = "0.5" />
< GradientStop Color = "Silver" Offset = "0.0" />
</ LinearGradientBrush >
</ Setter.Value >
</ Setter >
</ Trigger >
< Trigger Property = "ButtonBase.IsPressed" Value = "True" >
< Setter Property = "UIElement.Effect" >
< Setter.Value >
< DropShadowEffect BlurRadius = "10" Color = "Black" Direction = "0" Opacity = "0.6" RenderingBias = "Performance" ShadowDepth = "0" />
</ Setter.Value >
</ Setter >
</ Trigger >
</ ControlTemplate.Triggers >
</ ControlTemplate >
</ Button.Template > </ Button > |