Finally, I got lucky :) First of all, when we begin a Storyboard
on a Template
, it's not needed to set target name. Second, to Storyboard.Seek
take effect, we should begin the storyboard with isControllable = true
parameter. Together:
<Storyboard x:Key="Animator">
<DoubleAnimation From="0" To="360" Duration="12:00:00"
RepeatBehavior="Forever" Storyboard.TargetName="PART_HourHand"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"/>
<DoubleAnimation From="0" To="360" Duration="1:00:00"
RepeatBehavior="Forever" Storyboard.TargetName="PART_MinuteHand"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"/>
<DoubleAnimation From="0" To="360" Duration="00:01:00"
RepeatBehavior="Forever" Storyboard.TargetName="PART_SecondHand"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"/>
<DoubleAnimation From="0" To="360" Duration="00:01:00"
RepeatBehavior="Forever" Storyboard.TargetName="PART_Icon"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"/>
</Storyboard>
And the beginner code:
public override void OnApplyTemplate() {
base.OnApplyTemplate();
if (Animator == null)
return;
// begin the storyboard on `this` control with its own `Template` and controllable
Animator.Begin(this, Template, true);
// the storyboard has a duration of Forever -as you can see, we did not specified any duration. Is this a default behavior?
// while the storyboard has a duration of Forever, we have to set seekOrigin to BeginTime
Animator.Seek(this, DateTime.Now.TimeOfDay, TimeSeekOrigin.BeginTime);
}