WPF圆形按钮样式
前言
WPF圆形按钮样式设计思路:在button 里重新设计Template,主要包括设计Ellipse边框以及填充颜色。
提示:以下是本篇文章正文内容,下面案例可供参考
一、代码实现
效果图如下所示:
代码如下(示例):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="roundedButtonStyle" TargetType="Button">
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="roundButtonBackground" StrokeThickness="0.5" Fill="red">
<Ellipse.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="Gray"></GradientStop>
<GradientStop Offset="1" Color="LightGray"></GradientStop>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<Ellipse Margin="15,5,15,50">
<Ellipse.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="WhiteSmoke"></GradientStop>
<GradientStop Offset="1" Color="Transparent"></GradientStop>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
<ContentPresenter Name="GelButtonContent" VerticalAlignment="Center" HorizontalAlignment="Center"
Content="{TemplateBinding Content}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Ellipse.Fill" TargetName="roundButtonBackground">
<Setter.Value>
<RadialGradientBrush>
<GradientStop Offset="0" Color="Navy"></GradientStop>
<GradientStop Offset="1" Color="DeepSkyBlue"></GradientStop>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Ellipse.Fill" TargetName="roundButtonBackground">
<Setter.Value>
<RadialGradientBrush>
<GradientStop Offset="0" Color="#ffcc34"></GradientStop>
<GradientStop Offset="1" Color="#cc9900"></GradientStop>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>