ScreenOrientation Class

The orientation of the screen of a window (https://w3c.github.io/screen-orientation/#screenorientation-interface, screen.orientation), read from the ScreenOrientationProvider of the browsing context (ScreenOrientationOptions.Provider): its type and angle, its change event, and the orientation locks.

public sealed class ScreenOrientation : EventTarget
Inheritance
EventTarget ScreenOrientation

Properties

NameDescription
AngleGets the last known angle of the screen in degrees, from its natural orientation (the [[angle]] slot).
OnChangeGets or sets the event handler of the change event.
TypeGets the last known orientation of the screen (the [[type]] slot).

Gets the last known angle of the screen in degrees, from its natural orientation (the [[angle]] slot).

public ushort Angle { get; }

Gets or sets the event handler of the change event.

public Action<Event>? OnChange { get; set; }

Gets the last known orientation of the screen (the [[type]] slot).

public OrientationType Type { get; }

Methods

NameDescription
Lock(OrientationLockType)Locks the orientation of the screen (https://w3c.github.io/screen-orientation/#lock-method), with the ScreenOrientationProvider of the browsing context. The task completes once the screen is locked, after the change event. It fails with an InvalidStateError DomException when the document is not fully active, a SecurityError when it is sandboxed without allow-orientation-lock or hidden, a NotSupportedError when the screen cannot be locked, a NotAllowedError when the top-level document is not fullscreen, and an AbortError when another lock request or ScreenOrientation.Unlock replaces it, or the document is unloaded.
Unlock()Unlocks the orientation of the screen (https://w3c.github.io/screen-orientation/#unlock-method): the screen gets the orientation of the device back, and a pending lock request is aborted.

Lock(OrientationLockType)

ScreenOrientation.cs

Locks the orientation of the screen (https://w3c.github.io/screen-orientation/#lock-method), with the ScreenOrientationProvider of the browsing context. The task completes once the screen is locked, after the change event. It fails with an InvalidStateError DomException when the document is not fully active, a SecurityError when it is sandboxed without allow-orientation-lock or hidden, a NotSupportedError when the screen cannot be locked, a NotAllowedError when the top-level document is not fullscreen, and an AbortError when another lock request or ScreenOrientation.Unlock replaces it, or the document is unloaded.

public Task Lock(OrientationLockType orientation)

Unlocks the orientation of the screen (https://w3c.github.io/screen-orientation/#unlock-method): the screen gets the orientation of the device back, and a pending lock request is aborted.

public void Unlock()

Exceptions

DomException
The document is not fully active (InvalidStateError), or is sandboxed or hidden (SecurityError).

See also