Windows phone 7 如何反向调用故事板动画?
我有一个故事板动画,我想在一定条件下向后播放 Storyboard 1.autoreverse=true 这不是我想要的 好像我想更改“收件人和发件人”字段Windows phone 7 如何反向调用故事板动画?,windows-phone-7,windows-mobile,windows-phone-7.1,Windows Phone 7,Windows Mobile,Windows Phone 7.1,我有一个故事板动画,我想在一定条件下向后播放 Storyboard 1.autoreverse=true 这不是我想要的 好像我想更改“收件人和发件人”字段 <Storyboard x:Name="Storyboard1" Completed="Storyboard1_Completed"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(
<Storyboard x:Name="Storyboard1" Completed="Storyboard1_Completed">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="imageBack1">
<EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="imageBack1">
<DiscreteObjectKeyFrame KeyTime="0:0:0.25">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0:0:0.25" To="90" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="image1" d:IsOptimized="True"/>
</Storyboard>
看得见的
框架中不支持这一点,但是,您可以自己做:
private void Reverse(Storyboard sb)
{
DoubleAnimation anim = sb.Children.OfType<DoubleAnimation>().Single();
object temp = anim.From;
anim.From = anim.To;
anim.To = Temp;
}
我必须手动反转故事板:
// does not work.
public static Storyboard Reverse(Storyboard storyboard)
{
Storyboard newStoryboard = new Storyboard();
newStoryboard.SpeedRatio = storyboard.SpeedRatio;
foreach (var unknownChild in storyboard.Children)
{
if (unknownChild is DoubleAnimation)
{
DoubleAnimation child = unknownChild as DoubleAnimation;
DoubleAnimation newChild = new DoubleAnimation()
{
Duration = child.Duration,
// AutoReverse, BeginTime, FillBehaviour, RepeatBehaviour, SpeedRatio?
From = child.To,
To = child.From,
EasingFunction = child.EasingFunction
};
Storyboard.SetTargetProperty(newChild, Storyboard.GetTargetProperty(child));
Storyboard.SetTargetName(newChild, Storyboard.GetTargetName(child));
newStoryboard.Children.Add(newChild);
}
else if (unknownChild is ObjectAnimationUsingKeyFrames)
{
ObjectAnimationUsingKeyFrames child = unknownChild as ObjectAnimationUsingKeyFrames;
var newChild = new ObjectAnimationUsingKeyFrames()
{
Duration = (child as Timeline).Duration,
};
foreach (ObjectKeyFrame keyFrame in child.KeyFrames)
{
var newKeyFrame = new DiscreteObjectKeyFrame() {
KeyTime = KeyTime.FromTimeSpan(child.Duration.TimeSpan - keyFrame.KeyTime.TimeSpan),
Value = keyFrame.Value
};
newChild.KeyFrames.Add(newKeyFrame);
}
Storyboard.SetTargetName(newChild, Storyboard.GetTargetName(child));
Storyboard.SetTargetProperty(newChild, Storyboard.GetTargetProperty(child));
newStoryboard.Children.Add(newChild);
}
else
{
throw new Exception("type " + unknownChild + " not supported");
}
}
return newStoryboard;
}
然而,主要的问题似乎是,即使我传输TargetName和TargetProperty值,新的情节提要也无法找到正确的元素
不幸的是,我不知道Storyboard类如何确定它在Xaml树中的位置/它的资源父级://我对这个解决方案有一些疑问,因为您还需要重新定位/反转关键帧。@ColinE:您能说得更具体一点,看看我发布的代码吗?假设我想将“imageBack1”设置为“image1”,反之亦然。@Emo这是一个很好的观点。但是,我的回答中很重要的一点是“框架中不支持这个”。你必须自己编辑故事板来完成这一点。
// does not work.
public static Storyboard Reverse(Storyboard storyboard)
{
Storyboard newStoryboard = new Storyboard();
newStoryboard.SpeedRatio = storyboard.SpeedRatio;
foreach (var unknownChild in storyboard.Children)
{
if (unknownChild is DoubleAnimation)
{
DoubleAnimation child = unknownChild as DoubleAnimation;
DoubleAnimation newChild = new DoubleAnimation()
{
Duration = child.Duration,
// AutoReverse, BeginTime, FillBehaviour, RepeatBehaviour, SpeedRatio?
From = child.To,
To = child.From,
EasingFunction = child.EasingFunction
};
Storyboard.SetTargetProperty(newChild, Storyboard.GetTargetProperty(child));
Storyboard.SetTargetName(newChild, Storyboard.GetTargetName(child));
newStoryboard.Children.Add(newChild);
}
else if (unknownChild is ObjectAnimationUsingKeyFrames)
{
ObjectAnimationUsingKeyFrames child = unknownChild as ObjectAnimationUsingKeyFrames;
var newChild = new ObjectAnimationUsingKeyFrames()
{
Duration = (child as Timeline).Duration,
};
foreach (ObjectKeyFrame keyFrame in child.KeyFrames)
{
var newKeyFrame = new DiscreteObjectKeyFrame() {
KeyTime = KeyTime.FromTimeSpan(child.Duration.TimeSpan - keyFrame.KeyTime.TimeSpan),
Value = keyFrame.Value
};
newChild.KeyFrames.Add(newKeyFrame);
}
Storyboard.SetTargetName(newChild, Storyboard.GetTargetName(child));
Storyboard.SetTargetProperty(newChild, Storyboard.GetTargetProperty(child));
newStoryboard.Children.Add(newChild);
}
else
{
throw new Exception("type " + unknownChild + " not supported");
}
}
return newStoryboard;
}