如何旋转 xamarin 表单中的按钮?

How to rotate a button in xamarin forms?

我试图在 xamarin 中旋转一个按钮,但它什么也没做,我还尝试删除角半径,所以它不会是圆的,但它也什么也没做。我想把它旋转180度来翻转它。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ClickerApp.Page2"
             BackgroundColor="#202020">
    <StackLayout>
        <StackLayout VerticalOptions="Start" HorizontalOptions="Center" Rotation="0" RotationX="0" RotationY="0">
            <Button RotationY="180" Margin="35" x:Name="button1"  BorderWidth="10" BorderColor="Gray" CornerRadius="80" WidthRequest="160" HeightRequest="160" Clicked="button1_Clicked" Text="CLICK ME" HorizontalOptions="Center" VerticalOptions="Center"></Button>
        </StackLayout>
        <StackLayout VerticalOptions="EndAndExpand" HorizontalOptions="Center">
            <Button Margin="35" x:Name="button2"  BorderWidth="10" BorderColor="Gray" CornerRadius="80"  WidthRequest="160" HeightRequest="160" Clicked="button1_Clicked_1"  Text="CLICK ME" HorizontalOptions="Center" VerticalOptions="Center"></Button>
        </StackLayout>
    </StackLayout>
</ContentPage>

这是你需要的吗

如果是,Rotation="180" 就是答案

Xaml

<StackLayout BackgroundColor="LightPink" Padding="20" Margin="0" Spacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
     <Button BackgroundColor="LightGreen" Padding="0" Margin="0" WidthRequest="100" HeightRequest="100" CornerRadius="50"
             Text="Up" HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand"/>
     <Button BackgroundColor="LightBlue" Padding="0" Margin="0" WidthRequest="100" HeightRequest="100" CornerRadius="50"
             Text="Down" HorizontalOptions="CenterAndExpand" VerticalOptions="EndAndExpand" Rotation="180"/>
</StackLayout>

这是我的代码,请运行你的项目看看效果。

<StackLayout HorizontalOptions="Center" VerticalOptions="Start">
            <Button
                x:Name="button1"
                Margin="35"
                BorderColor="Gray"
                BorderWidth="10"
                CornerRadius="80"
                HeightRequest="160"
                HorizontalOptions="Center"
                Rotation="180"
                Text="CLICK ME"
                VerticalOptions="Center"
                WidthRequest="160" />
        </StackLayout>
        <StackLayout HorizontalOptions="Center" VerticalOptions="EndAndExpand">
            <Button
                x:Name="button2"
                Margin="35"
                BorderColor="Gray"
                BorderWidth="10"
                CornerRadius="80"
                HeightRequest="160"
                HorizontalOptions="Center"
                Text="CLICK ME"
                VerticalOptions="Center"
                WidthRequest="160" />
        </StackLayout>

截图: