15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

animations ❘ 1021<br />

Duration="0:0:3" AutoReverse="True"<br />

FillBehavior="Stop"<br />

RepeatBehavior="Forever"<br />

AccelerationRatio="0.9" DecelerationRatio="0.1"<br />

From="100" To="300" /><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Figures 35-29 <strong>and</strong> 35-30 show two states from the animated ellipse.<br />

code snippet AnimationDemo/EllipseWindow.xaml<br />

Animations are far more than typical window-dressing animation that appears onscreen<br />

constantly <strong>and</strong> immediately. You can add animation to business applications that make the<br />

user interface more responsive.<br />

The following example demonstrates a decent animation <strong>and</strong> also<br />

shows how the animation can be defined in a style. Within the Window<br />

resources you can see the style AnimatedButtonStyle for buttons. In<br />

the template, a rectangle-named outline is defined. This template has<br />

a thin stroke with the thickness set to 0.4.<br />

figure 35-30<br />

The template defines a property trigger for the IsMouseOver property. The<br />

EnterActions property of this trigger applies as soon as the mouse is moved over<br />

the button. The action to start is BeginStoryboard. BeginStoryboard is a trigger<br />

action that can contain <strong>and</strong> thus start Storyboard elements. The Storyboard<br />

element defines a DoubleAnimation to animate a double value. The property<br />

value that is changed in this animation is the Rectangle.StrokeThickness of the<br />

Rectangle element with the name outline. The value is changed in a smooth way<br />

by 1.2, as the By property specifies, for a time length of 0.3 seconds as specified by<br />

the Duration property. At the end of the animation, the stroke thickness is reset<br />

to its original value because AutoReverse=“True“. To summarize: as soon as the<br />

mouse moves over the button, the thickness of the outline is incremented by 1.2 for<br />

0.3 seconds. Figure 35-31 shows the button without animation, <strong>and</strong> Figure 35-32<br />

shows the button 0.3 seconds after the mouse moved over it. (It’s just not possible<br />

to show the smooth animation <strong>and</strong> intermediate looks in a print medium.)<br />

figure 35-31<br />

figure 35-32<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

figure 35-29<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!