我有一个要求,我需要一个按钮在几秒钟内从屏幕的一端移动到另一端(水平)。我试过这个并且在某种程度上有效。
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="button">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
<!--<EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="{Binding MainPage.width}">-->
<EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="-1283.725">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseIn"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="button">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
<!--<EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="{Binding Path=MainPage.height}">-->
<EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="-467.732">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseIn"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
但问题是由于屏幕尺寸和屏幕方向。在大屏幕上它停在中间。我想动态设置EasingDoubleKeyFrame 的值。代码背后或绑定或任何其他方式。
但我不想在 Code Behind 中编写整个故事板。
我可以使用获取屏幕宽度和高度
Rect bounds = Window.Current.Bounds;
static double height = 0;
static double width = 0;
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
height = bounds.Height;
width = -1 * bounds.Width;
}
让我知道是否有简单的方法。