首页 > 代码库 > WPF 制作圆角按钮

WPF 制作圆角按钮

在程序对应坐置插入以下代码,或是先拖一个按钮控件到窗体中,再替换对应的代码。

修改 CornerRadius="18,3,18,3"  就可以改变圆角大小

按钮效果:

 <Button Content="Button" HorizontalAlignment="Left" Margin="19,10,0,0" VerticalAlignment="Top" Width="75" Height="59">            <Button.Template>                <ControlTemplate TargetType="{x:Type Button}">                    <Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="0" CornerRadius="18,3,18,3" Name="PART_Background">                        <Border.Background>                            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">                                <GradientStop Color="#33CC33" Offset="0.0" />                                <GradientStop Color="Orange" Offset="0.5" />                                <GradientStop Color="LightYellow" Offset="0.0" />                            </LinearGradientBrush>                        </Border.Background>                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />                    </Border>                    <ControlTemplate.Triggers>                        <Trigger Property="UIElement.IsMouseOver" Value="http://www.mamicode.com/True">                            <Setter Property="Border.Background" TargetName="PART_Background">                                <Setter.Value>                                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">                                        <GradientStop Color="Lime" Offset="0.0" />                                        <GradientStop Color="#66CC33" Offset="0.5" />                                        <GradientStop Color="Gold" Offset="0.0" />                                    </LinearGradientBrush>                                </Setter.Value>                            </Setter>                        </Trigger>                        <Trigger Property="ButtonBase.IsPressed" Value="http://www.mamicode.com/True">                            <Setter Property="UIElement.Effect">                                <Setter.Value>                                    <DropShadowEffect BlurRadius="10" Color="#FF0033" Direction="0" Opacity="0.6" RenderingBias="Performance" ShadowDepth="0" />                                </Setter.Value>                            </Setter>                        </Trigger>                    </ControlTemplate.Triggers>                </ControlTemplate>            </Button.Template>        </Button>

  

WPF 制作圆角按钮