Mega Code Archive

 
Categories / Silverlight / Animations
 

DoubleAnimationUsingKeyFrames and SplineDoubleKeyFrame

<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="buttonDownSB">       <DoubleAnimationUsingKeyFrames Storyboard.TargetName="myButton" Storyboard.TargetProperty="(FrameworkElement.Width)" BeginTime="00:00:00">         <SplineDoubleKeyFrame KeyTime="00:00:00" Value="102"/>         <SplineDoubleKeyFrame KeyTime="00:00:01" Value="50"/>       </DoubleAnimationUsingKeyFrames>       <DoubleAnimationUsingKeyFrames Storyboard.TargetName="myButton" Storyboard.TargetProperty="(FrameworkElement.Height)" BeginTime="00:00:00">         <SplineDoubleKeyFrame KeyTime="00:00:00" Value="102"/>         <SplineDoubleKeyFrame KeyTime="00:00:01" Value="50"/>       </DoubleAnimationUsingKeyFrames>     </Storyboard>     <Storyboard x:Name="buttonDownReverseSB">       <DoubleAnimationUsingKeyFrames Storyboard.TargetName="myButton" Storyboard.TargetProperty="(FrameworkElement.Width)" BeginTime="00:00:00">         <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>         <SplineDoubleKeyFrame KeyTime="00:00:01" Value="102"/>       </DoubleAnimationUsingKeyFrames>       <DoubleAnimationUsingKeyFrames Storyboard.TargetName="myButton" Storyboard.TargetProperty="(FrameworkElement.Height)" BeginTime="00:00:00">         <SplineDoubleKeyFrame KeyTime="00:00:00" Value="50"/>         <SplineDoubleKeyFrame KeyTime="00:00:01" Value="102"/>       </DoubleAnimationUsingKeyFrames>     </Storyboard>   </UserControl.Resources>   <Grid x:Name="LayoutRoot" Background="White">     <Button HorizontalAlignment="Left" Margin="8,8,0,0" Width="102" Content="Button" VerticalAlignment="Top" Height="102" x:Name="myButton" Click="myButton_Click"/>     <TextBlock x:Name="myTextBlock" HorizontalAlignment="Left" Margin="8,128,0,125" VerticalAlignment="Stretch" Width="102" Text="" TextWrapping="Wrap"/>     </Grid> </UserControl> //File: Page.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SilverlightApplication3 {     public partial class MainPage : UserControl     {         public MainPage()         {             InitializeComponent();         }         public bool buttonCompleted;         public void myButton_Click(object sender, RoutedEventArgs e)         {             buttonCompleted = false;             buttonDownSB.Begin();             buttonDownSB.Completed += new EventHandler(buttonDownSB_Completed);         }         void buttonDownSB_Completed(object sender, EventArgs e)         {             buttonDownReverseSB.Begin();             buttonDownReverseSB.Completed += new EventHandler(buttonDownReverseSB_Completed);         }         void buttonDownReverseSB_Completed(object sender, EventArgs e)         {             myTextBlock.Text = "Completed";             buttonCompleted = true;         }     } }