Other Animations
In the right side, you can see that the 1st Rectangle is same as above, I am simply using ColorAnimation to animate the color.
2nd Rectangle object, I have specified the Storyboard.TargetProperty="Height" and specified the From and To property with Duration to animate the height of the object. In addition to that I have again added ColorAnimation to the same object and animating the color. You can specify more than one animation behavior to a particular object.
3rd object, this is nothing but a Rectangle object but I have not specified Stroke property and the Width is only 5 so it is looking like a line. To rotate it I have specified its Storyboard.TargetProperty="(Rectangle.RenderTransform).Angle property and From, To as 0 and 360 respectiverly. But you will also notice that this object is under 2nd BeginStoryboard because I want it to follow the Duration property different than the 1st one. I have also specified ColorAnimation> to animate the color while it is rotating.
4th TextBlock object, I have specified the Opacity property as the Storyboard.TargetProperty value and changing the value of opacity from 0.0 to 1.0.
5th Ellipse object, I have specified Storyboard.TargetProperty="Offset" and From To property to animate the color of the Ellipse
Important Properties
AutoReverse: This property will automatically reverse the animation to the begining point, I have used it in the Ellipse object.
RepeatBehavior: This property will let you specify the repeat behavior of the animation. If you want your animation to continue forever, you may specify Forever or you can specify 1x or 2x ie. one time or two times.
<Canvas xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<EventTrigger.Actions>
<!-- 1st Storyboard -->
<BeginStoryboard>
<Storyboard AutoReverse="True" RepeatBehavior="Forever" Duration="0:0:2">
<ColorAnimation Storyboard.TargetName="objectToAnimate"
Storyboard.TargetProperty="(Fill).(Color)"
From="Black" To="Yellow" Duration="0:0:1"/>
<DoubleAnimation Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="Height"
From="0" To="150" Duration="0:0:1"/>
<ColorAnimation Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="(Fill).(Color)"
From="Red" To="White" Duration="0:0:1"/>
<DoubleAnimation Storyboard.TargetName="textblock1"
Storyboard.TargetProperty="Opacity"
From="0.0" To="1.0" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
<!-- 2nd Storyboard -->
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="rectangle2" AutoReverse="False"
RepeatBehavior="Forever" Storyboard.TargetProperty="(Rectangle.RenderTransform).Angle"
From="0" To="360" Duration="0:0:3"/>
<ColorAnimation Storyboard.TargetName="rectangle2" RepeatBehavior="Forever"
Storyboard.TargetProperty="(Fill).(Color)" From="Blue" To="Red" Duration="0:0:3"/>
<DoubleAnimation Storyboard.TargetName="elOffset1" Storyboard.TargetProperty="Offset"
From="0.5" To="0.0" RepeatBehavior="Forever" AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="elOffset2" Storyboard.TargetProperty="Offset"
From="1.0" To="0.5" RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Canvas.Triggers>
<Rectangle x:Name="objectToAnimate" Canvas.Left="5" Fill="Red" Canvas.Top="15"
Height="50" Width="50" Stroke="Blue" StrokeThickness="3" />
<Rectangle x:Name="rectangle1" Canvas.Left="70" Fill="Red" Canvas.Top="15"
Height="50" Width="50" />
<Rectangle x:Name="rectangle2" Canvas.Left="30" Fill="Black" Canvas.Top="110"
Height="25" Width="5">
<Rectangle.RenderTransform>
<RotateTransform Angle="30"/>
</Rectangle.RenderTransform>
</Rectangle>
<TextBlock x:Name="textblock1" Canvas.Left="10" Canvas.Top="200" Text="DotNetFunda.com"
FontSize="21" FontStyle="Normal" FontWeight="ExtraBold" FontFamily="Arial" FontStretch="ExtraExpanded">
<TextBlock.Foreground>
<RadialGradientBrush>
<GradientStop Color="Green" Offset="0.25"/>
<GradientStop Color="Blue" Offset="0.6" />
<GradientStop Color="Brown" Offset="1" />
</RadialGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<Ellipse Canvas.Left="15" Canvas.Top="235" Width="150" Height="150">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop x:Name="elOffset1" Color="Red" Offset="0.0"/>
<GradientStop x:Name="elOffset2" Color="Yellow" Offset="0.50"/>
<GradientStop x:Name="elOffset3" Color="White" Offset="1.0"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Canvas>
|