当前位置: 首页>>代码示例>>C#>>正文


C# Timeline.CurrentTimeInvalidated事件代码示例

本文整理汇总了C#中System.Windows.Media.Animation.Timeline.CurrentTimeInvalidated事件的典型用法代码示例。如果您正苦于以下问题:C# Timeline.CurrentTimeInvalidated事件的具体用法?C# Timeline.CurrentTimeInvalidated怎么用?C# Timeline.CurrentTimeInvalidated使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。


在下文中一共展示了Timeline.CurrentTimeInvalidated事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TimelineCurrentTimeInvalidatedExample

/*
   This example shows how to register for the
   CurrentTimeInvalidated event
   using a Timeline. 

*/

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.TimingBehaviors
{

    public class TimelineCurrentTimeInvalidatedExample : Page {

        private TextBlock currentTimeTextBlock;
        public TimelineCurrentTimeInvalidatedExample()
        {
            
            // Create a name scope.
            NameScope.SetNameScope(this, new NameScope());
            
            WindowTitle = "GetAnimationBaseValue Example";
            StackPanel myPanel = new StackPanel();
            myPanel.Margin = new Thickness(20);     
            
            // Create a rectangle.
            Rectangle animatedRectangle = new Rectangle();
            animatedRectangle.Width = 100;
            animatedRectangle.Height = 50;
            animatedRectangle.Margin = new Thickness(50);
            animatedRectangle.Fill = Brushes.Orange;
            animatedRectangle.Stroke = Brushes.Gray;
            animatedRectangle.StrokeThickness = 2;
            
            // Create a RotateTransform.
            RotateTransform animatedTransform = new RotateTransform();
            animatedTransform.Angle = 0;
            this.RegisterName("animatedTransform", animatedTransform);
            animatedRectangle.RenderTransform = animatedTransform;
            animatedRectangle.RenderTransformOrigin = new Point(0.5,0.5);
            myPanel.Children.Add(animatedRectangle);
            this.Content = myPanel;

            // Create a TextBlock to show the storyboard's current time.
            currentTimeTextBlock = new TextBlock();
            myPanel.Children.Add(currentTimeTextBlock);
            
            // Animate the RotateTransform's angle using a Storyboard.
            DoubleAnimation angleAnimation = new DoubleAnimation(0,360, TimeSpan.FromSeconds(5));
            angleAnimation.RepeatBehavior = RepeatBehavior.Forever;
            Storyboard.SetTargetName(angleAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(angleAnimation, 
                new PropertyPath(RotateTransform.AngleProperty));
  
            Storyboard theStoryboard = new Storyboard();
            theStoryboard.Children.Add(angleAnimation);            
            
            // Register the CurrentTimeInvalidated event.
            // You must register for events before you begin 
            // the storyboard.
            theStoryboard.CurrentTimeInvalidated += 
                new EventHandler(storyboard_CurrentTimeInvalidated);
            
            // Start the storyboard.
            theStoryboard.Begin(animatedRectangle, true);
        }
        
        private void storyboard_CurrentTimeInvalidated(object sender, EventArgs e)
        {

            // Sender is the clock that was created for this storyboard.
            Clock storyboardClock = (Clock)sender;
            
            // Update the TextBlock with the storyboard's current time.
            currentTimeTextBlock.Text = storyboardClock.CurrentTime.ToString();       
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Media.Animation,代码行数:85,代码来源:Timeline.CurrentTimeInvalidated


注:本文中的System.Windows.Media.Animation.Timeline.CurrentTimeInvalidated事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。