2016-05-05 7 views
0

私は現在、このコースを通っています。C#最後のエラーが残っている最初のレッスンの最後にはまってしまいました。手伝う?ヘッドファーストC# - 第1章不動産アニメは動作しません

は本当にこれが問題のあるコードです

enter image description here

それを感謝...アニメーション化するプロパティがそれ Storyboard.SetTargetProperty(アニメーション、propertyToAnimate)の末尾にある、ありがとうございました。

using System; 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Data; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Imaging; 
    using System.Windows.Shapes; 

    using System.Windows.Media.Animation; 



    namespace Save_The_Human 
    { 
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     Random random = new Random(); 
     private double To; 

     private void startButton_Click(object sender, RoutedEventArgs e) 
     { 
      AddEnemy(); 
     } 
     private void AddEnemy() 
     { 
      ContentControl enemy = new ContentControl(); 
      enemy.Template = Resources["EnemyTemplate"] as ControlTemplate; 
      AnimateEnemy(enemy, 0, playArea.ActualWidth - 100, "(Canvas.Left)"); 
      AnimateEnemy(enemy, random.Next((int)playArea.ActualHeight - 100), 
       random.Next((int)playArea.ActualHeight - 100), "(Canvas.Top)"); 
      playArea.Children.Add(enemy); 
     } 

     private void AnimateEnemy(ContentControl enemy, double from, double to, string propertyToAnimate) 
     { 
      Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; 
      DoubleAnimation animation = new DoubleAnimation(); 
      { 
       var From = from; 
       To = to; 
       var Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6))); 
      }; 
      Storyboard.SetTarget(animation, enemy); 
      Storyboard.SetTargetProperty(animation, propertyToAnimate); 
      storyboard.Children.Add(animation); 
      storyboard.Begin(); 
     } 
    } 

} 
+0

私は問題はちょうどあなたが共有しているコードに見ることによって説明することができないと考えています。 'SetTarget'や' SetTargetProperty'メソッドに問題があるかもしれません。 –

+0

コンパイル時にエラーが発生しますか?コードはここでの例とほぼ同じです。https://msdn.microsoft.com/library/windows/apps/br210503 - 私が見ることのできる唯一の違いは、この例ではSetTargetを含む行がSetTargetProperty –

答えて

1

.NETの一部のバージョンまたはそれに類するもののように見えます。

あなたはそれにAnimateEnemy方法と呼び出しの宣言を置き換えることによって、それを修正することができます:

... 
AnimateEnemy(enemy, 0, playArea.ActualWidth - 25, new PropertyPath("(Canvas.Left)")); 
AnimateEnemy(enemy, random.Next((int)playArea.ActualHeight - 25), random.Next((int)playArea.ActualHeight - 25), new PropertyPath("(Canvas.Top)")); 
... 
private void AnimateEnemy(ContentControl enemy, double from, double to, PropertyPath propertyToAnimate) 
... 
+0

助けてくれてありがとう: – Vitta

+0

こんにちはドミトリー、Nadeemここに私を助けてくださいこのhttps://stackoverflow.com/questions/49187419/store-excel-file-using-c-sharp-console-application-in-特定の場所 – BNN

関連する問題