Partager via


MediaElement.Position Property

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

Gets or sets the current position of progress through the media's playback time.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property Position As TimeSpan
public TimeSpan Position { get; set; }

Property Value

Type: System.TimeSpan
The amount of time since the beginning of the media. The default is a TimeSpan with value 0:0:0.

Remarks

Dependency property identifier field: PositionProperty

Use this property to set to a specific position within the media. This property is settable, rather than there being a specific MediaElement.Seek method.

If the media does not support seek operations (which is the case for live streaming media), setting this property will have no effect on media playback. Check the value of CanSeek before attempting to set Position.

If Position is settable, then the following run-time value constraints apply:

  • If Position is set to a negative value, the value will revert to a TimeSpan with value 0:0:0.

  • If Position is set to a value larger than the media's NaturalDuration, then the NaturalDuration is set as Position

XAML usage for this property is not shown. You generally should not set this value in XAML, because until the media source is loaded there is no guarantee that the media can be positioned (it could be streaming, and therefore cannot be positioned). After MediaOpened is raised, check the value of CanSeek. If it is true, then the media can be positioned, and then you can set Position in code. XAML usage is technically possible however, and can be set using an attribute string in the format [days.]hours:minutes:seconds[.fractionalSeconds]. See BufferingTime for further guidance on the XAML grammar for timespans; a Position is parsed by the same methodology.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.