首页 > 代码库 > 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 制作圆角按钮
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。