Show / Hide Table of Contents

Struct Duration

Represents the duration of time that a Timeline is active.

Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: System.Windows
Assembly: OpenSilver.dll
Syntax
public struct Duration

Constructors

| Improve this Doc View Source

Duration(TimeSpan)

Initializes a new instance of the Duration structure with the supplied TimeSpan value.

Declaration
public Duration(TimeSpan timeSpan)
Parameters
Type Name Description
System.TimeSpan timeSpan

Represents the initial time interval of this duration.

Exceptions
Type Condition
System.ArgumentException

timeSpan evaluates as less than System.TimeSpan.Zero.

Properties

| Improve this Doc View Source

Automatic

Gets a Duration value that is automatically determined.

Declaration
public static readonly Duration Automatic { get; }
Property Value
Type Description
Duration

A Duration initialized to an automatic value.

| Improve this Doc View Source

Forever

Gets a Duration value that represents an infinite interval.

Declaration
public static readonly Duration Forever { get; }
Property Value
Type Description
Duration

A Duration initialized to a forever value.

| Improve this Doc View Source

HasTimeSpan

Gets a value that indicates if this Duration represents a TimeSpan value.

Declaration
public readonly bool HasTimeSpan { get; }
Property Value
Type Description
System.Boolean

true if this Duration is a TimeSpan value; otherwise, false.

| Improve this Doc View Source

TimeSpan

Gets the TimeSpan value that this Duration represents.

Declaration
public readonly TimeSpan TimeSpan { get; }
Property Value
Type Description
System.TimeSpan

The TimeSpan value that this Duration represents.

Exceptions
Type Condition
System.InvalidOperationException

The Duration does not represent a TimeSpan.

Methods

| Improve this Doc View Source

Add(Duration)

Adds the value of the specified Duration to this Duration.

Declaration
public Duration Add(Duration duration)
Parameters
Type Name Description
Duration duration

An instance of Duration that represents the value of the current instance plus duration.

Returns
Type Description
Duration

If each involved Duration has values, a Duration that represents the combined values. Otherwise this method returns null.

| Improve this Doc View Source

Compare(Duration, Duration)

Compares one Duration value to another.

Declaration
public static int Compare(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first instance of Duration to compare.

Duration t2

The second instance of Duration to compare.

Returns
Type Description
System.Int32

If t1 is less than t2, a negative value that represents the difference. If t1 is equal to t2, a value of 0. If t1 is greater than t2, a positive value that represents the difference.

| Improve this Doc View Source

Equals(Object)

Determines whether a specified object is equal to a Duration.

Declaration
public override bool Equals(object value)
Parameters
Type Name Description
System.Object value

Object to check for equality.

Returns
Type Description
System.Boolean

true if value is equal to this Duration; otherwise, false.

Overrides
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

Equals(Duration)

Determines whether a specified Duration is equal to this Duration.

Declaration
public bool Equals(Duration duration)
Parameters
Type Name Description
Duration duration

The Duration to check for equality.

Returns
Type Description
System.Boolean

true if duration is equal to this Duration; otherwise, false.

| Improve this Doc View Source

Equals(Duration, Duration)

Determines whether two Duration values are equal.

Declaration
public static bool Equals(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

First Duration to compare.

Duration t2

Second Duration to compare.

Returns
Type Description
System.Boolean

true if t1 is equal to t2; otherwise, false.

| Improve this Doc View Source

GetHashCode()

Gets a hash code for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

The hash code identifier.

Overrides
System.ValueType.GetHashCode()
| Improve this Doc View Source

Plus(Duration)

Returns the specified instance of Duration.

Declaration
public static Duration Plus(Duration duration)
Parameters
Type Name Description
Duration duration

The instance of Duration to get.

Returns
Type Description
Duration

An instance of Duration.

| Improve this Doc View Source

Subtract(Duration)

Subtracts the specified Duration from this Duration.

Declaration
public Duration Subtract(Duration duration)
Parameters
Type Name Description
Duration duration

The Duration to subtract from this Duration.

Returns
Type Description
Duration

The subtracted Duration.

| Improve this Doc View Source

ToString()

Converts a Duration to a System.String representation.

Declaration
public override string ToString()
Returns
Type Description
System.String

A System.String representation of this Duration.

Overrides
System.ValueType.ToString()

Operators

| Improve this Doc View Source

Addition(Duration, Duration)

Adds two Duration values together.

Declaration
public static Duration operator +(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first Duration to add.

Duration t2

The second Duration to add.

Returns
Type Description
Duration

If both Duration values have TimeSpan values, this method returns the sum of those two values. If either value is set to Automatic, the method returns Automatic. If either value is set to Forever, the method returns Forever. If either t1 or t2 has no value, this method returns null.

| Improve this Doc View Source

Equality(Duration, Duration)

Determines whether two Duration cases are equal.

Declaration
public static bool operator ==(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first Duration to compare.

Duration t2

The second Duration to compare.

Returns
Type Description
System.Boolean

true if both Duration values have equal property values, or if all Duration values are null. Otherwise, this method returns false.

| Improve this Doc View Source

GreaterThan(Duration, Duration)

Determines if one Duration is greater than another.

Declaration
public static bool operator>(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The Duration value to compare.

Duration t2

The second Duration value to compare.

Returns
Type Description
System.Boolean

true if both t1 and t2 have values and t1 is greater than t2; otherwise, false.

| Improve this Doc View Source

GreaterThanOrEqual(Duration, Duration)

Determines whether a Duration is greater than or equal to another.

Declaration
public static bool operator >=(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first instance of Duration to compare.

Duration t2

The second instance of Duration to compare.

Returns
Type Description
System.Boolean

true if both t1 and t2 have values and t1 is greater than or equal to t2; otherwise, false.

| Improve this Doc View Source

Implicit(TimeSpan to Duration)

Implicitly creates a Duration from a given TimeSpan.

Declaration
public static implicit operator Duration(TimeSpan timeSpan)
Parameters
Type Name Description
System.TimeSpan timeSpan

TimeSpan from which a Duration is implicitly created.

Returns
Type Description
Duration

A created Duration.

Exceptions
Type Condition
System.ArgumentException

timeSpan evaluates as less than System.TimeSpan.Zero.

| Improve this Doc View Source

Inequality(Duration, Duration)

Determines if two Duration cases are not equal.

Declaration
public static bool operator !=(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first Duration to compare.

Duration t2

The second Duration to compare.

Returns
Type Description
System.Boolean

true if exactly one of t1 or t2 represent a value, or if they both represent values that are not equal; otherwise, false.

| Improve this Doc View Source

LessThan(Duration, Duration)

Determines if a Duration is less than the value of another instance.

Declaration
public static bool operator <(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first Duration to compare.

Duration t2

The second Duration to compare.

Returns
Type Description
System.Boolean

true if both t1 and t2 have values and t1 is less than t2; otherwise, false.

| Improve this Doc View Source

LessThanOrEqual(Duration, Duration)

Determines if a Duration is less than or equal to another.

Declaration
public static bool operator <=(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The Duration to compare.

Duration t2

The Duration to compare.

Returns
Type Description
System.Boolean

true if both t1 and t2 have values and t1 is less than or equal to t2; otherwise, false.

| Improve this Doc View Source

Subtraction(Duration, Duration)

Subtracts the value of one Duration from another.

Declaration
public static Duration operator -(Duration t1, Duration t2)
Parameters
Type Name Description
Duration t1

The first Duration.

Duration t2

The Duration to subtract.

Returns
Type Description
Duration

If each Duration has values, a Duration that represents the value of t1 minus t2. If t1 has a value of Forever and t2 has a value of TimeSpan, this method returns Forever. Otherwise this method returns null.

| Improve this Doc View Source

UnaryPlus(Duration)

Returns the specified Duration.

Declaration
public static Duration operator +(Duration duration)
Parameters
Type Name Description
Duration duration

The Duration to get.

Returns
Type Description
Duration

The Duration operation result.

  • Improve this Doc
  • View Source