2
我有一個需求,我需要一個按鈕在幾秒鐘內從屏幕的一端移動到另一端(水平)。我嘗試了這個,並在一定程度上起作用。XAML:從代碼背後設置Storyboard動畫的值
<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;
}
讓我知道,如果有一個簡單的方法獲取屏幕寬度&高度。