效果图
1、修改button边框和圆角
<Button Text="BlueButton"
BorderColor="Blue"
BorderRadius = "5"
BorderWidth = "2"/>
2、制作圆形button
新建CircularButton.cs,并创建CircularButton类
public class CircularButton : Button
{
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
CornerRadius = (int)width / 2;
}
}
3、制作圆形ImageButton并使其显示
新建MyImageButton.cs,并创建MyImageButton类
public class MyImageButton : ImageButton
{
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
CornerRadius = (int)width / 2;
}
}
4、引用显示
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:test2"
x:Class="test2.MainPage">
<StackLayout>
<Button Text="BlueButton"
BorderColor="Blue"
BorderRadius = "5"
BorderWidth = "2"/>
<local:CircularButton HorizontalOptions="Center" WidthRequest="100" HeightRequest="100" Text=""/>
<local:MyImageButton HorizontalOptions="Center" WidthRequest="50" HeightRequest="50" Source="walk.png" BackgroundColor="LightGray"/>
</StackLayout>
</ContentPage>