2010-08-21 50 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(); 
    } 

    } 
} 
相关问题