2012-03-01 10 views
0

私はある条件で逆向きに再生したいストーリーボードアニメーションを持っています。ストーリーボードアニメーションを後方に呼び出す方法は?

storyboard1.autoreverse = true;

iは

が、私はフィールド

<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> 

答えて

0

から&に変更したいのような枠組みの中で、このためにはサポートされていません欲しいものではありません、しかし、自分で行うのは簡単です:

次のように使用することができ
private void Reverse(Storyboard sb) 
{ 
    DoubleAnimation anim = sb.Children.OfType<DoubleAnimation>().Single(); 
    object temp = anim.From; 
    anim.From = anim.To; 
    anim.To = Temp; 
} 

+0

残念ながら、私はそれはそれはリソースの親の/ XAMLツリー内の場所ですかストーリーボードクラスの数字アウト分かりません。 –

+0

@ColinE:私が投稿したコードを見て、 "imageBack1"を "image1"に、その逆にしたいと思うと、少し具体的になるかもしれません。 – user1235555

+0

@エモ良い点。しかし、私の声明では、「これをフレームワークでサポートしていない」という私の声明は、私の答えの中で重要なポイントです。 StoryBoardを編集することでこれを自分で行う必要があります。 – ColinE

0

私は手動でストーリーボードを逆にしました:

// 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値を転送しても、新しいストーリーボードが正しいの要素を見つけることができないということのようです。あなたが同様にキーフレームを逆転/再配置する必要がありますので、私はこのソリューションについていくつかの疑問を持っている/

関連する問題