2012-04-16 6 views
1

私は背後にあるコードでは、タイルのアニメーションを作成したい、またはあなたがこのGOLのためのプロジェクトを知っていれば、plsはストーリーボードでStackpanelの余白をアニメーション化するにはどうすればよいですか?

Deployment.Current.Dispatcher.BeginInvoke(() => 
        { 
         while(true){ 
         Duration duration = new Duration(TimeSpan.FromSeconds(0.15)); 

         // Create two DoubleAnimations and set their properties. 
         DoubleAnimation myDoubleAnimation1 = new DoubleAnimation(); 

         myDoubleAnimation1.Duration = duration; 
         myDoubleAnimation1.From = -173 
         myDoubleAnimation1.To = 173; 
         Storyboard sb = new Storyboard(); 
         sb.Duration = duration; 

         sb.Children.Add(myDoubleAnimation1); 

         Storyboard.SetTarget(myDoubleAnimation1, image); 

         // Set the attached properties of Canvas.Left and Canvas.Top 
         // to be the target properties of the two respective DoubleAnimations. 
         Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath(StackPanel.MarginProperty)); 

         // Begin the animation. 
         sb.Begin();} 
        }); 
+0

マージンの種類はダブルではありません(ダブルアニメーションを使用するものです)。 Marginプロパティの内容をアニメーション化する必要があります。これは、構造体であるため、行うことができないかどうかわかりません。あなたは何をしようとしているのですか。 –

+2

ストーリーボードを無限ループの後に実際に作成していますか? – Clemens

+0

[Animating Margin Bottom Silverlight](http://stackoverflow.com/questions/6507954/animating-margin-bottom-silverlight) – ColinE

答えて

3

ThicknessAnimationを使用して私を書き、私はそれを使用したいと思いますが、それは仕事をdoesnt't DoubleAnimationの代わりにそれはほぼ同じです。

編集:

あなたはアニメーションの無限の使用Timeline.RepeatBehaviorを作りたい場合は。ここで

myThicknessAnimation1.RepeatBehavior = RepeatBehavior.Forever; 
+0

あなたのLPLに答えてくれてありがとう、XAMLでそれを書くことができますか? – user1272388

+0

私があなたに与えたThicknessAnimationのリンクの例のセクションをご覧ください。 – LPL

1

誰もが必要な場合は、実施例である:

//ラベルのためのマージンをアニメーションを、右から左に「ラベル」と命名。 300から0

var sb = new Storyboard(); 
      var ta = new ThicknessAnimation(); 
      ta.BeginTime = new TimeSpan(0); 
      ta.SetValue(Storyboard.TargetNameProperty, "label"); 
      Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); 

      ta.From = new Thickness(300, 30, 0, 0); 
      ta.To = new Thickness(0, 30, 0, 0); 
      ta.Duration = new Duration(TimeSpan.FromSeconds(3)); 

      sb.Children.Add(ta); 
      sb.Begin(this); 
関連する問題