Table of Contents

Class TopLevel

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Base class for top-level widgets.

[TemplatePart("PART_TransparencyFallback", typeof(Border))]
public abstract class TopLevel : ContentControl, INotifyPropertyChanged, IDataContextProvider, IThemeVariantHost, IResourceHost, IResourceNode, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IDataTemplateHost, ISetterValue, ILayoutRoot, IRenderRoot, ICloseable, IStyleHost, ILogicalRoot, ILogical, ITextInputMethodRoot, IInputRoot, IInputElement
Inheritance
TopLevel
Implements
Derived
Inherited Members
Extension Methods

Remarks

This class acts as a base for top level widget. It handles scheduling layout, styling and rendering as well as tracking the widget's ClientSize.

Constructors

TopLevel(ITopLevelImpl)

Initializes a new instance of the TopLevel class.

public TopLevel(ITopLevelImpl impl)

Parameters

impl ITopLevelImpl

The platform-specific window implementation.

TopLevel(ITopLevelImpl, IAvaloniaDependencyResolver?)

Initializes a new instance of the TopLevel class.

public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver? dependencyResolver)

Parameters

impl ITopLevelImpl

The platform-specific window implementation.

dependencyResolver IAvaloniaDependencyResolver

The dependency resolver to use. If null the default dependency resolver will be used.

Fields

ActualThemeVariantProperty

public static readonly StyledProperty<ThemeVariant> ActualThemeVariantProperty

Field Value

StyledProperty<ThemeVariant>

ActualTransparencyLevelProperty

Defines the ActualTransparencyLevel property.

public static readonly DirectProperty<TopLevel, WindowTransparencyLevel> ActualTransparencyLevelProperty

Field Value

DirectProperty<TopLevel, WindowTransparencyLevel>

AutoSafeAreaPaddingProperty

Defines the AutoSafeAreaPadding attached property.

public static readonly AttachedProperty<bool> AutoSafeAreaPaddingProperty

Field Value

AttachedProperty<bool>

BackRequestedEvent

Defines the BackRequested event.

public static readonly RoutedEvent<RoutedEventArgs> BackRequestedEvent

Field Value

RoutedEvent<RoutedEventArgs>

ClientSizeProperty

Defines the ClientSize property.

public static readonly DirectProperty<TopLevel, Size> ClientSizeProperty

Field Value

DirectProperty<TopLevel, Size>

FrameSizeProperty

Defines the FrameSize property.

public static readonly DirectProperty<TopLevel, Size?> FrameSizeProperty

Field Value

DirectProperty<TopLevel, Size?>

PointerOverElementProperty

Defines the PointerOverElement property.

public static readonly StyledProperty<IInputElement?> PointerOverElementProperty

Field Value

StyledProperty<IInputElement>

RequestedThemeVariantProperty

public static readonly StyledProperty<ThemeVariant?> RequestedThemeVariantProperty

Field Value

StyledProperty<ThemeVariant>

SystemBarColorProperty

Defines the SystemBarColor attached property.

public static readonly AttachedProperty<SolidColorBrush?> SystemBarColorProperty

Field Value

AttachedProperty<SolidColorBrush>

TransparencyBackgroundFallbackProperty

Defines the TransparencyBackgroundFallback property.

public static readonly StyledProperty<IBrush> TransparencyBackgroundFallbackProperty

Field Value

StyledProperty<IBrush>

TransparencyLevelHintProperty

Defines the TransparencyLevelHint property.

public static readonly StyledProperty<IReadOnlyList<WindowTransparencyLevel>> TransparencyLevelHintProperty

Field Value

StyledProperty<IReadOnlyList<WindowTransparencyLevel>>

Properties

ActualTransparencyLevel

Gets the achieved WindowTransparencyLevel that the platform was able to provide.

public WindowTransparencyLevel ActualTransparencyLevel { get; }

Property Value

WindowTransparencyLevel

BypassFlowDirectionPolicies

Gets a value indicating whether control bypass FlowDirecton policies.

protected override bool BypassFlowDirectionPolicies { get; }

Property Value

bool

Remarks

Related to FlowDirection system and returns false as default, so if FlowDirection is RTL then control will get a mirror presentation. For controls that want to avoid this behavior, override this property and return true.

ClientSize

Gets or sets the client size of the window.

public Size ClientSize { get; protected set; }

Property Value

Size

Clipboard

Gets the platform's clipboard implementation

public IClipboard? Clipboard { get; }

Property Value

IClipboard

FocusManager

Gets focus manager of the root.

public IFocusManager? FocusManager { get; }

Property Value

IFocusManager

Remarks

Focus manager can be null only if window wasn't initialized yet.

FrameSize

Gets or sets the total size of the window.

public Size? FrameSize { get; protected set; }

Property Value

Size?

InputPane

public IInputPane? InputPane { get; }

Property Value

IInputPane

InsetsManager

public IInsetsManager? InsetsManager { get; }

Property Value

IInsetsManager

Launcher

public ILauncher Launcher { get; }

Property Value

ILauncher

PlatformImpl

Gets the platform-specific window implementation.

public ITopLevelImpl? PlatformImpl { get; }

Property Value

ITopLevelImpl

PlatformSettings

Represents a contract for accessing top-level platform-specific settings.

public IPlatformSettings? PlatformSettings { get; }

Property Value

IPlatformSettings

Remarks

PlatformSettings can be null only if window wasn't initialized yet.

RenderScaling

The scaling factor to use in rendering.

public double RenderScaling { get; }

Property Value

double

RendererDiagnostics

Gets a value indicating whether the renderer should draw specific diagnostics.

public RendererDiagnostics RendererDiagnostics { get; }

Property Value

RendererDiagnostics

RequestedThemeVariant

Gets or sets the UI theme variant that is used by the control (and its child elements) for resource determination. The UI theme you specify with ThemeVariant can override the app-level ThemeVariant.

public ThemeVariant? RequestedThemeVariant { get; set; }

Property Value

ThemeVariant

Remarks

Setting RequestedThemeVariant to Default will apply parent's actual theme variant on the current scope.

Screens

Gets platform screens implementation.

public Screens? Screens { get; }

Property Value

Screens

StorageProvider

File System storage service used for file pickers and bookmarks.

public IStorageProvider StorageProvider { get; }

Property Value

IStorageProvider

TransparencyBackgroundFallback

Gets or sets the IBrush that transparency will blend with when transparency is not supported. By default this is a solid white brush.

public IBrush TransparencyBackgroundFallback { get; set; }

Property Value

IBrush

TransparencyLevelHint

Gets or sets the WindowTransparencyLevel that the TopLevel should use when possible. Accepts multiple values which are applied in a fallback order. For instance, with "Mica, Blur" Mica will be applied only on platforms where it is possible, and Blur will be used on the rest of them. Default value is an empty array or "None".

public IReadOnlyList<WindowTransparencyLevel> TransparencyLevelHint { get; set; }

Property Value

IReadOnlyList<WindowTransparencyLevel>

Methods

GetAutoSafeAreaPadding(Control)

Gets if auto safe area padding is enabled.

public static bool GetAutoSafeAreaPadding(Control control)

Parameters

control Control

The main view attached to the toplevel, or the toplevel.

Returns

bool

GetSystemBarColor(Control)

Helper for getting the color of the platform's system bars.

public static SolidColorBrush? GetSystemBarColor(Control control)

Parameters

control Control

The main view attached to the toplevel, or the toplevel.

Returns

SolidColorBrush

The current color of the platform's system bars.

GetTopLevel(Visual?)

Gets the TopLevel for which the given Visual is hosted in.

public static TopLevel? GetTopLevel(Visual? visual)

Parameters

visual Visual

The visual to query its TopLevel

Returns

TopLevel

The TopLevel

InvalidateMirrorTransform()

Computes the HasMirrorTransform value according to the FlowDirection and BypassFlowDirectionPolicies

protected override void InvalidateMirrorTransform()

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is added to a rooted visual tree.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnClosed(EventArgs)

Raises the Closed event.

protected virtual void OnClosed(EventArgs e)

Parameters

e EventArgs

The event args.

OnOpened(EventArgs)

Raises the Opened event.

protected virtual void OnOpened(EventArgs e)

Parameters

e EventArgs

The event args.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

RequestAnimationFrame(Action<TimeSpan>)

Enqueues a callback to be called on the next animation tick

public void RequestAnimationFrame(Action<TimeSpan> action)

Parameters

action Action<TimeSpan>

RequestPlatformInhibition(PlatformInhibitionType, string)

Requests a PlatformInhibitionType to be inhibited. The behavior remains inhibited until the return value is disposed. The available set of PlatformInhibitionTypes depends on the platform. If a behavior is inhibited on a platform where this type is not supported the request will have no effect.

public Task<IDisposable> RequestPlatformInhibition(PlatformInhibitionType type, string reason)

Parameters

type PlatformInhibitionType
reason string

Returns

Task<IDisposable>

SetAutoSafeAreaPadding(Control, bool)

Enabled or disables whenever TopLevel should automatically adjust paddings depending on the safe area.

public static void SetAutoSafeAreaPadding(Control control, bool value)

Parameters

control Control

The main view attached to the toplevel, or the toplevel.

value bool

Value to be set.

SetSystemBarColor(Control, SolidColorBrush?)

Helper for setting the color of the platform's system bars.

public static void SetSystemBarColor(Control control, SolidColorBrush? color)

Parameters

control Control

The main view attached to the toplevel, or the toplevel.

color SolidColorBrush

The color to set.

StartRendering()

protected void StartRendering()

StopRendering()

protected void StopRendering()

TryGetPlatformHandle()

Trys to get the platform handle for the TopLevel-derived control.

public IPlatformHandle? TryGetPlatformHandle()

Returns

IPlatformHandle

An IPlatformHandle describing the window handle, or null if the handle could not be retrieved.

Events

BackRequested

Occurs when physical Back Button is pressed or a back navigation has been requested.

public event EventHandler<RoutedEventArgs> BackRequested

Event Type

EventHandler<RoutedEventArgs>

Closed

Fired when the window is closed.

public event EventHandler? Closed

Event Type

EventHandler

Opened

Fired when the window is opened.

public event EventHandler? Opened

Event Type

EventHandler

ScalingChanged

Gets or sets a method called when the TopLevel's scaling changes.

public event EventHandler? ScalingChanged

Event Type

EventHandler