15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1020 ❘ ChaPTer 35 cOre wpf<br />

< RowDefinition Height="60" / ><br />

< RowDefinition Height="30" / ><br />

< /Grid.RowDefinitions ><br />

< Image Grid.Row="0" Width="48" Margin="2,2,2,1"<br />

Source="{Binding ImagePath}" / ><br />

< TextBlock Grid.Row="1" FontSize="14"<br />

HorizontalAlignment="Center" Margin="5"<br />

Text="{Binding Name}" / ><br />

< /Grid ><br />

< /DataTemplate ><br />

< /Setter.Value ><br />

< /Setter ><br />

< /Style ><br />

animaTions<br />

With animations you can make a smooth transition using moving elements, color changes, transforms, <strong>and</strong><br />

so on. WPF makes it easy to create animations. You can animate the value of any dependency property.<br />

Different animation classes exist to animate the values of different properties, depending on their type.<br />

The major elements of animations are as follows:<br />

➤<br />

➤<br />

➤<br />

Timeline — Defi nes how a value changes over time. Different kinds of timelines are available for<br />

changing different types of values. The base class for all timelines is Timeline . To animate a double ,<br />

the class DoubleAnimation can be used. Int32Animation is the animation class for int values.<br />

PointAnimation is used to animate points, <strong>and</strong> ColorAnimation to animate colors.<br />

Storyboard — Used to combine animations. The Storyboard class itself is derived from the base class<br />

TimelineGroup , which derives from Timeline . With DoubleAnimation you can animate a double<br />

value; with Storyboard you combine all the animations that belong together.<br />

Triggers — Start <strong>and</strong> stop animations. You ’ ve seen property triggers previously. They fi re when a property<br />

value changes. You can also create an event trigger. An event trigger fi res when an event occurs.<br />

The namespace for animation classes is System.Windows.Media.Animation.<br />

Timeline<br />

A Timeline defi nes how a value changes over time. The fi rst example animates the size of an ellipse. Here<br />

a DoubleAnimation timeline changes to a double value. The Triggers property of the Ellipse class is set<br />

to an EventTrigger . The event trigger is fi red when the ellipse is loaded as defi ned with the RoutedEvent<br />

property of the EventTrigger . BeginStoryboard is a trigger action that begins the storyboard. With<br />

the storyboard, a DoubleAnimation element is used to animate the Width property of the Ellipse class.<br />

The animation changes the width of the ellipse from 100 to 300 within three seconds, <strong>and</strong> reverses the<br />

animation after three seconds. The animation ColorAnimation animates the color from the ellipseBrush<br />

which is used to fi ll the ellipse:<br />

< Ellipse Height="50" Width="100" ><br />

< Ellipse.Fill ><br />

< SolidColorBrush x:Name="ellipseBrush" Color="SteelBlue" / ><br />

< /Ellipse.Fill ><br />

< Ellipse.Triggers ><br />

< EventTrigger RoutedEvent="Ellipse.Loaded" ><br />

< EventTrigger.Actions ><br />

< BeginStoryboard ><br />

< Storyboard Duration="00:00:06" RepeatBehavior="Forever" ><br />

< DoubleAnimation<br />

Storyboard.TargetProperty="(Ellipse.Width)"<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!