可以使用方向感應器,讓您的device`s方向,然後設置您的Button.Projection天使
參考鏈接:https://msdn.microsoft.com/en-us/windows/uwp/devices-sensors/use-the-orientation-sensor
public sealed partial class MainPage : Page
{
private SimpleOrientationSensor simpleorientation;
private double? Current = 0;
public MainPage()
{
this.InitializeComponent();
simpleorientation = SimpleOrientationSensor.GetDefault();
if (simpleorientation != null)
{
simpleorientation.OrientationChanged += new TypedEventHandler<SimpleOrientationSensor, SimpleOrientationSensorOrientationChangedEventArgs>(OrientationChanged);
}
}
private async void OrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
{
SimpleOrientation orientation = args.Orientation;
switch (orientation)
{
case SimpleOrientation.NotRotated:
Rotate(0);
break;
case SimpleOrientation.Rotated90DegreesCounterclockwise:
Rotate(90);
break;
case SimpleOrientation.Rotated180DegreesCounterclockwise:
Rotate(180);
break;
case SimpleOrientation.Rotated270DegreesCounterclockwise:
Rotate(270);
break;
case SimpleOrientation.Faceup:
break;
case SimpleOrientation.Facedown:
break;
default:
break;
}
});
}
private void Rotate(double value)
{
MyAnimation.From = Current;
MyAnimation.To = (360 - value);
myStoryBoard.Begin();
Current = MyAnimation.To;
}
}
XAML代碼:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button
x:Name="TestButton"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="button">
<Button.Projection>
<PlaneProjection x:Name="Projection" RotationZ="0" />
</Button.Projection>
</Button>
<Grid.Resources>
<Storyboard x:Name="myStoryBoard">
<DoubleAnimation
x:Name="MyAnimation"
Storyboard.TargetName="Projection"
Storyboard.TargetProperty="RotationZ"
Duration="0:0:1" />
</Storyboard>
</Grid.Resources>
</Grid>
感謝您的回覆。這不僅僅是我在屏幕上放置網格的動畫按鈕嗎?我感興趣的是如何在屏幕按鈕上旋轉硬件。 – user2081328