Controlling Animations Programmatically : Animations « Animations « Silverlight






Controlling Animations Programmatically

Controlling Animations Programmatically
    


<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
    <UserControl.Resources>
          <Storyboard x:Name="FadeIt">
                <DoubleAnimation Storyboard.TargetName="btnFade"
                     Storyboard.TargetProperty="(UIElement.Opacity)"
                        From=".25" To="1" Duration="00:00:01"/>
        </Storyboard>
          <Storyboard x:Name="SizeIt">
               <DoubleAnimation Storyboard.TargetName="btnSize"
                      Storyboard.TargetProperty="(UIElement.RenderTransform).
                       (TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                        From="1" To="2" Duration="00:00:01"/>
                <DoubleAnimation Storyboard.TargetName="btnSize"
                      Storyboard.TargetProperty="(UIElement.RenderTransform).
                     (TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                        From="1" To="2" Duration="00:00:01"/>
        </Storyboard>
    </UserControl.Resources>
     <Grid x:Name="LayoutRoot" Background="Black">
         <Button x:Name="btnSize" Content="Resize">
            <Button.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Button.RenderTransform>
        </Button>
        <Button x:Name="btnFade" Content="Fade In"
                Height="50" Width="150" Margin="100,120,0,0"
                HorizontalAlignment="Left"  VerticalAlignment="Top"
                Opacity="0.25"/>
    </Grid>
</UserControl>

//File: Page.xaml.cs
 using System;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;

 namespace SilverlightApplication3
 {
     public partial class MainPage : UserControl
     {
         public MainPage()
          {
             InitializeComponent();
             btnFade.MouseEnter += new MouseEventHandler(btnFade_MouseEnter);
             btnSize.MouseEnter += new MouseEventHandler(btnSize_MouseEnter);

             btnFade.MouseLeave += new MouseEventHandler(btnFade_MouseLeave);
             btnSize.MouseLeave += new MouseEventHandler(btnSize_MouseLeave);
          }
          void btnSize_MouseEnter(object sender, MouseEventArgs e)
          {
              SizeIt.Begin();
          }
          void btnFade_MouseEnter(object sender, MouseEventArgs e)
          {
              FadeIt.Begin();
          }
          void btnSize_MouseLeave(object sender, MouseEventArgs e)
          {
              SizeIt.Stop();
          }
          void btnFade_MouseLeave(object sender, MouseEventArgs e)
          {
             FadeIt.Stop();
          }
     }
 }

   
    
    
    
  








Related examples in the same category

1.Using Simple Animations with ObjectsUsing Simple Animations with Objects
2.Creating from to AnimationsCreating from to Animations
3.Rectangles and Multiple Animation EffectsRectangles and Multiple Animation Effects
4.Chained Animation EffectsChained Animation Effects
5.Point Animation EffectsPoint Animation Effects
6.Starting an animation with a trigger
7.Create a bounce animationCreate a bounce animation
8.Move a rectangle from position (0,0) to position (300,0) in 5 secondsMove a rectangle from position (0,0) to position (300,0) in 5 seconds
9.Enlarge Button In Xaml
10.Two Animations
11.Animation without acceleration or deceleration
12.Animation with a slow speed
13.Animate EndPointAnimate EndPoint
14.Animate StartPointAnimate StartPoint
15.XAML Only Animation
16.Four Sided Bounce
17.Start the animation with Path is loaded
18.Brush animationBrush animation
19.Control the animation from codeControl the animation from code
20.Wipe out an ImageWipe out an Image
21.Rotating buttonRotating button
22.Simultaneous animationSimultaneous animation
23.Fade Image StoryboardFade Image Storyboard
24.Repetition durationRepetition duration
25.Timer triggered Animation
26.Use code to control DoubleAnimationUse code to control DoubleAnimation
27.Animation Ease effect
28.Animate transformationAnimate transformation
29.Grow a ButtonGrow a Button
30.3D Animation