あなた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