WPF : StoryBoard用法

Storyboard storyBoard =   new Storyboard();
DoubleAnimation ani
=   new DoubleAnimation();
           
ani.From
=   0 ;
ani.To
=   360 ;
ani.Duration
=   new Duration(TimeSpan.FromMilliseconds( 5000 ));
ani.RepeatBehavior
= RepeatBehavior.Forever;
storyBoard.Children.Add(ani);

this .RegisterName( " mRotationX " , mRotationX);
Storyboard.SetTargetName(ani,
" mRotationX " );
Storyboard.SetTargetProperty(ani,
new PropertyPath(AxisAngleRotation3D.AngleProperty));
storyBoard.Begin(
this, true ); /////true表示controlable


            TimeSpan timeSpan = TimeSpan.FromMilliseconds( 250 );

           
// 创建一个Animation, 设置起点, 终点, 时段
            DoubleAnimation ani =   new DoubleAnimation();
            ani.From
=   4 ;
            ani.To
=   0 ;
            ani.Duration
=   new Duration(timeSpan);           
            Storyboard.SetTargetName(ani,
" Opacity " );
            Storyboard.SetTargetProperty(ani,
new PropertyPath(WindowMain.OpacityProperty));

           
// 创建一个Animation, 设置起点, 终点, 时段
            DoubleAnimation ani2 =   new DoubleAnimation();
            ani2.From
=   this .mZoomSlider.Value;
            ani2.To
=   2 ;
            ani2.Duration
=   new Duration(timeSpan);           
            Storyboard.SetTargetName(ani2,
" Zoom " );
            Storyboard.SetTargetProperty(ani2,
new PropertyPath(Slider.ValueProperty));


           
// 创建StoryBoard
            Storyboard storyBoard =   new Storyboard();
              storyBoard.FillBehavior = FillBehavior.Stop;
            storyBoard.Completed
+=   new EventHandler(storyBoard_Completed);
            storyBoard.Children.Add(ani);
            storyBoard.Children.Add(ani2);

           
this .RegisterName( " Opacity " , this );
           
this .RegisterName( " Zoom " , this .mZoomSlider);           
            storyBoard.Begin(
this, true ); /////////////////////////////////true表示controlable


或者

< Window.Triggers >
   
< EventTrigger RoutedEvent = " Window.Loaded "   >
       
< BeginStoryboard >
           
< Storyboard Name = " myStoryBoardX " >
               
< DoubleAnimation
        Storyboard.TargetName
= " rotationX "  
        Storyboard.TargetProperty
= " Angle "  
        From
= " 0 " To = " 360 " Duration = " 0:0:15 " RepeatBehavior = " Forever " />
           
</ Storyboard >
       
</ BeginStoryboard >
       
< BeginStoryboard >
           
< Storyboard Name = " myStoryBoardY " >
               
< DoubleAnimation
        Storyboard.TargetName
= " rotationY "  
        Storyboard.TargetProperty
= " Angle "  
        From
= " 0 " To = " 360 " Duration = " 0:0:12 " RepeatBehavior = " Forever " />
           
</ Storyboard >
       
</ BeginStoryboard >
   
</ EventTrigger >
</ Window.Triggers >

你可能感兴趣的:(WPF)