Have It Your Way
April 3, 2006
New York City
Some people like the second hands on their clocks and watches to move smoothly. Others prefer that the second hand make a sudden step every second. It's a personal preference, and not the type of thing people argue about.
If you're coding a clock using WPF animation, you can do it either way, as the SecondHandSteps.xaml file demonstrates:
-
<!-- ==================================================
SecondHandSteps.xaml (c) 2006 by Charles Petzold
================================================== -->
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Line Stroke="Black" StrokeThickness="3"
X1="0" Y1="0" X2="0" Y2="-100"
Canvas.Left="150" Canvas.Top="150">
<Line.RenderTransform>
<RotateTransform x:Name="xform1" />
</Line.RenderTransform>
</Line>
<Line Stroke="Black" StrokeThickness="3"
X1="0" Y1="0" X2="0" Y2="-100"
Canvas.Left="450" Canvas.Top="150">
<Line.RenderTransform>
<RotateTransform x:Name="xform2" />
</Line.RenderTransform>
</Line>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="xform1"
Storyboard.TargetProperty="Angle"
From="0" To="360" Duration="0:1"
RepeatBehavior="Forever" />
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="xform2"
Storyboard.TargetProperty="Angle"
RepeatBehavior="Forever"
IsCumulative="True">
<DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="6" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
</Canvas>