.NET Framework 类库
Timeline..::.CurrentTimeInvalidated 事件

更新:2007 年 11 月

在时间线 ClockCurrentTime 属性更新时发生。

命名空间:  System.Windows.Media.Animation
程序集:  PresentationCore(在 PresentationCore.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation

语法

Visual Basic(声明)
Public Event CurrentTimeInvalidated As EventHandler
Visual Basic (用法)
Dim instance As Timeline
Dim handler As EventHandler

AddHandler instance.CurrentTimeInvalidated, handler
C#
public event EventHandler CurrentTimeInvalidated
Visual C++
public:
 event EventHandler^ CurrentTimeInvalidated {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
J#
/** @event */
public void add_CurrentTimeInvalidated (EventHandler value)
/** @event */
public void remove_CurrentTimeInvalidated (EventHandler value)
JScript
JScript 不支持事件。
XAML 属性用法
<object CurrentTimeInvalidated="EventHandler" .../>
备注

如果希望在时间线的 ClockCurrentTime 更新时收到通知,请使用 CurrentStateInvalidated 事件。

EventHandler 事件处理程序的 Object 参数为时间线的 Clock

虽然此事件处理程序看上去与时间线相关联,但它实际向为此时间线创建的 Clock 注册。有关更多信息,请参见计时事件概述

示例

下面的示例演示如何为 CurrentTimeInvalidated 事件进行注册。

C#
/*

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



    }

}
平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0
另请参见

参考

其他资源

标记 :


Page view tracker