UWPのアニメーションに関する質問があります。私はトップにタップすると、スライドショー(ショー)またはスライドショー(ほぼ完全に隠れる)という、私のアプリの一番下にメニューを持っていたい。私は以前WPFを学習していましたが、ThicknessAnimationを使用してコントロールのマージンを移動してスライドさせることができることを知っています。残念ながら、UWPではThicknessAnimationsを使用できませんので、別の方法を探しました。私は任意のFrameworkElement(これを再利用できるように)で動作させたいと思っています。結局、私はこの解決策を思い付いた:それは作品c#UWPのスライド要素
/// <summary>
/// Adds a vertical slide animation
/// </summary>
/// <param name="storyboard">The storyboard to add the animation to</param>
/// <param name="seconds">The time the animation will take</param>
/// <param name="offset">The distance the element will cover (nagative is up, positive is down)</param>
public static void AddVerticalSlide(this Storyboard storyboard, FrameworkElement element, float seconds, double offset)
{
var slideAnimation = new ObjectAnimationUsingKeyFrames();
for (int i = 0; i <= 100; ++i)
{
double scalar = (double)i/100;
slideAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame
{
Value = new Thickness(0, scalar*offset, 0, -scalar*offset),
KeyTime = TimeSpan.FromSeconds(scalar*seconds),
});
}
//slideAnimation.Duration = TimeSpan.FromSeconds(seconds);
// Set the target and target property
Storyboard.SetTarget(slideAnimation, element);
Storyboard.SetTargetProperty(slideAnimation, "(FrameworkElement.Margin)");
// Add the animation to the storyboard
storyboard.Children.Add(slideAnimation);
}
、良さそうに見えますが、ここで私はこの質問を求めている理由です:それは正しいかどうかはわかりません。私のゲーは、途中で手動で100ポイントを定義し、このアニメーションを使ってオブジェクトを各ポイントに移動するよりも、オブジェクトをスライドさせるより良い方法があるということです。