我得到了这个UserControl,它是一个大约10行10列的网格。每个单元格包含1个文本块或1-6个图像。 我想要做的是动画每行上的所有元素进行幻灯片放映。但是我找不到一种方法来为整个Grid设置动画。如何做到这一点。
我无法将所有元素都包装在stackpanel / canvas中,因为它将它们放在同一列中......
任何人都有解决方案吗?
由于
答案 0 :(得分:1)
所以我提出了一个有效的解决方案,它正在发挥作用。也许不是那么优雅,但它可以做它应该做的并且在Lumia 920设备上运行得非常好。
void CreateLoadAnimationForRow(int row, int startTime)
{
foreach (var child in LayoutRoot.Children.Cast<FrameworkElement>().Where(x => Grid.GetRow(x) == row))
{
AddToStoryboard(child, startTime);
}
}
void AddToStoryboard(FrameworkElement element, int startTime)
{
element.RenderTransform = new CompositeTransform();
var doubleAnimation = new DoubleAnimation
{
From = -200,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(1)),
BeginTime = TimeSpan.FromMilliseconds(startTime)
};
var objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames()
{
BeginTime = TimeSpan.FromMilliseconds(startTime + 10)
};
var discreteObjectKeyFrame = new DiscreteObjectKeyFrame()
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
Value = Visibility.Visible
};
objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);
IEasingFunction easingFunction = new SineEase();
easingFunction.Ease(2);
doubleAnimation.EasingFunction = easingFunction;
Storyboard.SetTarget(objectAnimationUsingKeyFrames, element);
Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, new PropertyPath("Visibility"));
Storyboard.SetTarget(doubleAnimation, element);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(FrameworkElement.RenderTransform).(CompositeTransform.TranslateX)"));
storyboardSlideIn.Children.Add(doubleAnimation);
storyboardSlideIn.Children.Add(objectAnimationUsingKeyFrames);
}