【问题标题】:System.Windows.Media.Animation.AnimationTimeline)' is inaccessible due to its protection levelSystem.Windows.Media.Animation.AnimationTimeline)' 由于其保护级别而无法访问
【发布时间】:2011-04-02 02:38:10
【问题描述】:

您好,我正在尝试以编程方式控制 WPF 动画,但出现上述错误,有人可以帮助解决该错误 - 对 c# 不太熟悉 - 谢谢

using System;

使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 System.Windows; 使用 System.Windows.Controls; 使用 System.Windows.Data; 使用 System.Windows.Documents; 使用 System.Windows.Input; 使用 System.Windows.Media; 使用 System.Windows.Media.Imaging; 使用 System.Windows.Navigation; 使用 System.Windows.Shapes; 使用 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(); 
    }

   }

}

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    这意味着您不能使用“new”创建“clock”对象的实例。您可以使用 animation.CreateClock() 方法来做到这一点,就像您的 StartAnimation() 方法中的方法一样。无论如何,对您的代码稍作调整应该可以使其正常工作。希望下面的代码能给你一个想法:

    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(); 
        }
    
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-26
      • 2011-09-01
      • 1970-01-01
      • 2011-02-07
      • 2012-01-25
      • 2022-01-18
      • 2019-06-28
      相关资源
      最近更新 更多