Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

Other important properties

Other important properties

The AccelerationRatio property accepts a value between 0.0 and 1.0 is a percentage of the animation duration, while the animation accelerates from the beginning.

The DecelerationRatio also receive values between 0.0 and 1.0 is actually a percentage of the animation duration, while the animation slows down.

The value of the AutoReverse property can be True or False. If the animation reaches the end, vice playback occurs when you choose the first value.

With using BeginTime property it is possible to delay the start of the animation. Format: hours:minutes:secons.

FillBehavior is the property to determine what happens when the animation is over. There are two possible values: HoldEnd and Stop.

The RepeatBehavior property specifies the number of times the animation is repeated.

The SpeedRatio property can change the playback speed of the animation relative to the parent timeline.

Example XI.3 ColorAnimation

<Grid>

        <Rectangle Width="100" Height="100" Fill="Black">

            <Rectangle.Triggers>

                <EventTrigger RoutedEvent="Rectangle.MouseDown">

                    <EventTrigger.Actions>

                       <BeginStoryboard>

                        <Storyboard>

                            <ColorAnimation To="Red" Duration="0:0:10"

                                            Storyboard.TargetProperty="Fill.Color"

                                            AutoReverse="True"

                                            AccelerationRatio="0.1"

                                            DecelerationRatio="0.6"/>

                        </Storyboard>

                    </BeginStoryboard>

                    </EventTrigger.Actions>

                </EventTrigger>

            </Rectangle.Triggers>

        </Rectangle>

</Grid>

Example XI.4 DoubleAnimation

XI.1. DoubleAnimation

 

<Window x:Class="DoubleAnimation.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="DoubleAnimation" Height="400" Width="350">

    <Window.Resources>

        <Storyboard x:Key="sbpicture"

                    FillBehavior="HoldEnd">

            <DoubleAnimation Storyboard.TargetName="rectmars"

                       Storyboard.TargetProperty="Width" From="1" To="300"

                       Duration="0:0:1" BeginTime="0:0:0"/>

            <DoubleAnimation Storyboard.TargetName="rectmars"

                       Storyboard.TargetProperty="Height" From="1" To="300"

                       Duration="0:0:1" BeginTime="0:0:1"/>

        </Storyboard>

        <Storyboard x:Key="sbheader"

                    FillBehavior="Stop">

            <ColorAnimation Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"

                       From="Red" To="White" Duration="0:0:1" BeginTime="0:0:0"/>

            <ColorAnimation Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"

                       From="White" To="Red" Duration="0:0:1" BeginTime="0:0:0.5"/>

            <ColorAnimation Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"

                       From="Red" To="White" Duration="0:0:1" BeginTime="0:0:1"/>

            <ColorAnimation Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"

                       From="White" To="Red" Duration="0:0:1" BeginTime="0:0:0"/>

            <ColorAnimation Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"

                       From="Red" To="White" Duration="0:0:1" BeginTime="0:0:0.5"/>

            <ColorAnimation Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"

                       From="White" To="Red" Duration="0:0:1" BeginTime="0:0:1"/>

        </Storyboard>

</Window.Resources>

<Grid>

        <StackPanel>

        <Button x:Name="button1" Click="button1_Click"

                Content="Open image"

                Width="100" Height="40"></Button>

            <Rectangle Height="5" x:Name="rect1" Width="300">

             <Rectangle.Fill>

               <LinearGradientBrush x:Name="brush" StartPoint="0,0"  EndPoint="1,1">

                        <GradientStop x:Name="stop1" Offset="0" Color="Red"/>

                        <GradientStop x:Name="stop2" Offset="0.5" Color="White"/>  

               </LinearGradientBrush>

             </Rectangle.Fill>

            </Rectangle>

                <Rectangle Name="rectmars" Width="1" Height="1" >

            <Rectangle.Fill>

                <ImageBrush ImageSource="Mars.jpg"/>

            </Rectangle.Fill>

        </Rectangle>

        </StackPanel>

    </Grid>

</Window>

Code-behind:

private void button1_Click(object sender, RoutedEventArgs e)

{

Storyboard sp = (Storyboard)TryFindResource("sbpicture");

Storyboard sh = (Storyboard)TryFindResource("sbheader");

sp.Begin();

sh.Begin();

}