在 Xamarin 中可以方便进行样式定义或不进行定义样式只修改属性而改变外观,如按钮的圆角可以通过 CornerRadius 属性设置
按钮使用圆角时,如果更改边框的颜色建议同时更改边框的宽度和边框颜色,在不同的平台下默认的样式不相同的,如果想要保持各个平台统一的外观,虽然这样不是好主意,那么请设置固定的值,而不是采用默认值
Font="Large" Text="选取PPT文件" HorizontalOptions="Center"CornerRadius="5"BackgroundColor="Transparent"BorderColor="Aquamarine" BorderWidth="2"/>
此时就创建了一个圆角的按钮,注意需要设置边框时同时设置 BorderColor 和 BorderWidth 两个值。因为在 UWP 中 BorderWidth 是 2 而在 Android 中是 0 也就是此时如果干掉了背景颜色,将看不到按钮的圆角
设置按钮背景透明可以通过设置 BackgroundColor 为 Transparent 属性
如果需要让按钮点击时呈现有趣的效果,可以通过 VisualStateManager 的方式定义
Font="Large" Text="选取PPT文件" HorizontalOptions="Center"CornerRadius="5"BackgroundColor="Transparent"BorderColor="Aquamarine" BorderWidth="2">x:Name="CommonStates">x:Name="Normal">Property="Scale"Value="1" />x:Name="Pressed">Property="Scale"Value="0.6" />x:Name="Released">Property="Scale"Value="2" />
这个项目所有代码放在 github :https://github.com/lindexi/lindexi_gd/tree/9fdafab123302ae7d7a2c9aecb590109218c4e72/JardalllojoHayeajemjuli 欢迎小伙伴访问