Duration.TimeSpan Property

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

Gets the TimeSpan value that this Duration represents.

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

Syntax

'Declaration
Public ReadOnly Property TimeSpan As TimeSpan
public TimeSpan TimeSpan { get; }

Property Value

Type: System.TimeSpan
The TimeSpan value that this Duration represents.

Exceptions

Exception Condition
InvalidOperationException

The Duration does not represent a TimeSpan.

Remarks

Getting this property raises an exception if the Duration does not represent a TimeSpan, for instance if the value is nulla null reference (Nothing in Visual Basic), or if the value is Forever or Automatic. To avoid the exception, you should write your code such that TimeSpan is checked only after HasTimeSpan is verified as true.

In the JavaScript API for Silverlight, only the Seconds property of a Duration is accessible, and the underlying time span value would have to be read in a seconds format. In the managed API for Silverlight, you can access the TimeSpan property and then manipulate the various TimeSpan APIs, such as Parse, FromSeconds, etc.

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.