如何使用xaml在xamarin中将按钮的形状从矩形更改为Circle

时间:2017-05-19 10:08:16

标签: c# xaml xamarin

我的活动中有一个矩形按钮。我应该换成圆形吗?如何使用XAML实现这一目标?

2 个答案:

答案 0 :(得分:1)

我通常使用此enter link description here 更改ShapeType

var box = new ShapeView
{
    ShapeType = ShapeType.Box,
    HeightRequest = 75,
    WidthRequest = 75,
    Color = Color.Navy,
    HorizontalOptions = LayoutOptions.Center,
    CornerRadius = 5,
    BorderColor = Color.Red,
    BorderWidth = 1f,
    Content = new Label
    {
        Text = "Touch me!",
        FontSize = Device.GetNamedSize(NamedSize.Micro, typeof (Label)),
        TextColor = Color.White,
        HorizontalOptions = LayoutOptions.Fill,
        VerticalOptions = LayoutOptions.Fill,
        VerticalTextAlignment = TextAlignment.Center,
        HorizontalTextAlignment = TextAlignment.Center,
    },
};

var tap = new TapGestureRecognizer
{
    Command = new Command(() => {
        this.DisplayAlert("Touched", "This shape responds to touch!", "Ok");
    })
};

box.GestureRecognizers.Add(tap);

答案 1 :(得分:0)

我认为这只能在具有cornerradius的IOS中实现,但我不认为这对于PCL或其他具有xaml的Xamarin解决方案是可行的。您可能必须制作自定义渲染器。