1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > WPF Button 设置圆角 CornerRadius属性的使用

WPF Button 设置圆角 CornerRadius属性的使用

时间:2022-06-05 00:02:48

相关推荐

WPF Button 设置圆角 CornerRadius属性的使用

在WPF,button的默认形态时长方形的,但是我们为了美观,通常需要将button的四个角设计的温和一点,在WPF中就需要用到这样一个属性CornerRadius。

首先我们要画一个button

<Button Click="SubmitButton" Style="{StaticResource NormalButton}" Content="确认" Background="#037AA6" Foreground="#FAFBFD" />

然后给button添加样式

<Style x:Key="NormalButton" TargetType="{x:Type Button}"><Setter Property="FontFamily" Value="GEInspiraSans-Bold" /><Setter Property="FontSize" Value="14" /><Setter Property="Height" Value="32"/><Setter Property="Width" Value="96"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Border CornerRadius="3" BorderBrush="#037AA6" BorderThickness="1" Background="{TemplateBinding Background}"><ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/></Border></ControlTemplate></Setter.Value></Setter></Style>

可以看到为border设置了CornerRadius属性,value为3,这个可以根据需求自定义圆角的弯曲度,同时上面将Background通过绑定的方式输入value,那么在画button的时候可以将值传入

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。