2010-08-21 88 views
1

您好我正在嘗試以編程方式控制WPF動畫,但獲取上述錯誤,有人可以幫助錯誤 - 不是很熟悉c# - 謝謝System.Windows.Media.Animation.AnimationTimeline)'由於其保護級別而無法訪問

using System; 

using System.Collections.Generic;使用System.Linq的 ; using System.Text;使用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.Navigation; using System.Windows.Shapes; using System.Windows.Media.Animation;

命名空間WpfApplication10 {/// /// 的互動邏輯Window1.xaml ///

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 
    } 
     AnimationClock clock; 
     void StartAnimation() 
    { 
     DoubleAnimation animate = new DoubleAnimation(); 
     animate.To = 300; 
     animate.Duration = new Duration(TimeSpan.FromSeconds(5)); 
     animate.RepeatBehavior = RepeatBehavior.Forever; 
     clock = animate.CreateClock(); 
     test.ApplyAnimationClock(Ellipse.WidthProperty, clock); 
    } 
    void PauseAnimation() 
    { 
     clock = new AnimationClock(); 
     clock.Controller.Pause(); 
    } 
    void ResumeAnimation() 
    { 
     clock.Controller.Resume(); 
    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     PauseAnimation(); 
    } 

    } 

}

回答

0

這意味着你不能創建 「時鐘」 的一個實例使用「新」的對象。您可以使用類似StartAnimation()方法中的animation.CreateClock()方法來完成此操作。無論如何,對你的代碼進行一些調整就可以使它工作。希望下面的代碼給你一個想法:

using System; 
using System.Windows.Media.Animation; 
using System.Windows; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Shapes; 

namespace WpfApplication10 { /// /// Interaction logic for Window1.xaml /// 

public partial class Window1: Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 

     DoubleAnimation animate = new DoubleAnimation(); 
     animate.To = 300; 
     animate.Duration = new Duration(TimeSpan.FromSeconds(5)); 
     animate.RepeatBehavior = RepeatBehavior.Forever; 
     clock = animate.CreateClock(); 
    } 

    AnimationClock clock; 
    void StartAnimation() 
    {   
     test.ApplyAnimationClock(Ellipse.WidthProperty, clock); 
    } 

    void PauseAnimation() 
    { 
     clock.Controller.Pause(); 
    } 

    void ResumeAnimation() 
    { 
     clock.Controller.Resume(); 
    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     StartAnimation(); 
    } 

    } 
} 
相關問題