Share via


Seek

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Moves a Storyboard object to a new position when the next clock tick occurs.

object.Seek(offset)

Arguments

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 quotation marks, colons, and periods are parts of the syntax):

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

- or -

"days"

Managed Equivalent

Seek

Remarks

Defining a TimeSpan is possible only through a type conversion syntax, when you set a property or call a method that takes TimeSpan as a type and specify the value as a delimited string. For more information, see the TimeSpan reference topic.

Example

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

<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  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>
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