Share via


Seek Method

Seeks this Storyboard to a new position when the next clock tick occurs.

XAML
Cannot use methods in XAML.
Scripting
object.Seek(offset)

Parameters

offset

TimeSpan

A positive or negative time value that describes the amount by which the timeline should move forward or backward from the beginning of the animation. The TimeSpan is specified as a string in the following format (in this syntax, the [] characters denote optional components of the string, but the quotes, colons and periods are all part of the syntax):

"[days.]hours:minutes:seconds[.fractionalSeconds]"
- or -
"days"

Remarks

Defining a TimeSpan is only possible through a type conversion syntax when setting a property or calling a method that takes TimeSpan as a type, with the value specified as a string in a delimited format, as documented in the Parameters section or on the TimeSpan page.

Examples

The following example shows how to use the Seek method. When you click on the rectangle created by the XAML below, the animation jumps to 3 seconds from the beginning of the animation.

XAML
<Canvas
  xmlns="https://schemas.microsoft.com/client/2007"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
  <Rectangle
    x:Name="MyAnimatedRectangle"
    Width="50"
    Height="100"
    Fill="Blue"
	MouseLeftButtonDown="SeekStoryboard"
	>
    <Rectangle.Triggers>
      <!-- Increases the width of the rectangle. -->
      <EventTrigger RoutedEvent="Rectangle.Loaded">
        <BeginStoryboard>
          <Storyboard x:Name="RectWidthStoryboard">
            <DoubleAnimation
              Storyboard.TargetName="MyAnimatedRectangle"
              Storyboard.TargetProperty="Width"
              From="50" To="550" Duration="0:0:5" />
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Rectangle.Triggers>
  </Rectangle>
</Canvas>
JavaScript
function SeekStoryboard(sender, eventArgs)
{
  // Get a reference to the Storyboard.
  var myStoryboard = sender.findName("RectWidthStoryboard");
  // Seek to 3 seconds after the animation begins.
  myStoryboard.Seek("0:0:3");
}

Applies To

Storyboard

See Also

Animation Overview
Interactive Animations Overview