Table of Contents

Class WindowBase

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Base class for top-level windows.

public class WindowBase : TopLevel, INotifyPropertyChanged, IDataContextProvider, IThemeVariantHost, IResourceHost, IResourceNode, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IDataTemplateHost, ISetterValue, ILayoutRoot, IRenderRoot, ICloseable, IStyleHost, ILogicalRoot, ILogical, ITextInputMethodRoot, IInputRoot, IInputElement
Inheritance
WindowBase
Implements
Derived
Inherited Members
Extension Methods

Remarks

This class acts as a base for top level windows such as Window and PopupRoot. It handles scheduling layout, styling and rendering as well as tracking the window ClientSize and IsActive state.

Constructors

WindowBase(IWindowBaseImpl)

public WindowBase(IWindowBaseImpl impl)

Parameters

impl IWindowBaseImpl

WindowBase(IWindowBaseImpl, IAvaloniaDependencyResolver?)

public WindowBase(IWindowBaseImpl impl, IAvaloniaDependencyResolver? dependencyResolver)

Parameters

impl IWindowBaseImpl
dependencyResolver IAvaloniaDependencyResolver

Fields

IsActiveProperty

Defines the IsActive property.

public static readonly DirectProperty<WindowBase, bool> IsActiveProperty

Field Value

DirectProperty<WindowBase, bool>

OwnerProperty

Defines the Owner property.

public static readonly DirectProperty<WindowBase, WindowBase?> OwnerProperty

Field Value

DirectProperty<WindowBase, WindowBase>

TopmostProperty

public static readonly StyledProperty<bool> TopmostProperty

Field Value

StyledProperty<bool>

Properties

DesktopScaling

Gets the scaling factor for Window positioning and sizing.

public double DesktopScaling { get; }

Property Value

double

IgnoreVisibilityChanges

protected bool IgnoreVisibilityChanges { get; }

Property Value

bool

IsActive

Gets a value that indicates whether the window is active.

public bool IsActive { get; }

Property Value

bool

Owner

Gets or sets the owner of the window.

public WindowBase? Owner { get; protected set; }

Property Value

WindowBase

PlatformImpl

public IWindowBaseImpl? PlatformImpl { get; }

Property Value

IWindowBaseImpl

Screens

Gets platform screens implementation.

public Screens Screens { get; }

Property Value

Screens

Topmost

Gets or sets whether this window appears on top of all other windows

public bool Topmost { get; set; }

Property Value

bool

Methods

Activate()

Activates the window.

public void Activate()

ArrangeCore(Rect)

Overrides the core arrange logic for windows.

protected override void ArrangeCore(Rect finalRect)

Parameters

finalRect Rect

The final arrange rect.

Remarks

The layout logic for top-level windows is different than for other controls because they don't have a parent, meaning that many layout properties handled by the default ArrangeCore (such as margins and alignment) make no sense.

ArrangeSetBounds(Size)

Called during the arrange pass to set the size of the window.

protected virtual Size ArrangeSetBounds(Size size)

Parameters

size Size

The requested size of the window.

Returns

Size

The actual size of the window.

EnsureInitialized()

Ensures that the window is initialized.

protected void EnsureInitialized()

Hide()

Hides the popup.

public virtual void Hide()

IsVisibleChanged(AvaloniaPropertyChangedEventArgs)

protected virtual void IsVisibleChanged(AvaloniaPropertyChangedEventArgs e)

Parameters

e AvaloniaPropertyChangedEventArgs

MeasureCore(Size)

Overrides the core measure logic for windows.

protected override Size MeasureCore(Size availableSize)

Parameters

availableSize Size

The available size.

Returns

Size

The measured size.

Remarks

The layout logic for top-level windows is different than for other controls because they don't have a parent, meaning that many layout properties handled by the default MeasureCore (such as margins and alignment) make no sense.

OnClosed(EventArgs)

Raises the Closed event.

protected override void OnClosed(EventArgs e)

Parameters

e EventArgs

The event args.

OnOpened(EventArgs)

Raises the Opened event.

protected override 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.

OnResized(WindowResizedEventArgs)

Raises the Resized event.

protected virtual void OnResized(WindowResizedEventArgs e)

Parameters

e WindowResizedEventArgs

An EventArgs that contains the event data.

Show()

Shows the window.

public virtual void Show()

Events

Activated

Fired when the window is activated.

public event EventHandler? Activated

Event Type

EventHandler

Deactivated

Fired when the window is deactivated.

public event EventHandler? Deactivated

Event Type

EventHandler

PositionChanged

Fired when the window position is changed.

public event EventHandler<PixelPointEventArgs>? PositionChanged

Event Type

EventHandler<PixelPointEventArgs>

Resized

Occurs when the window is resized.

public event EventHandler<WindowResizedEventArgs>? Resized

Event Type

EventHandler<WindowResizedEventArgs>

Remarks

Although this event is similar to the SizeChanged event, they are conceptually different:

  • Resized is a window-level event, fired when a resize notification arrives from the platform windowing subsystem. The event args contain details of the source of the resize event in the Reason property. This event is raised before layout has been run on the window's content.
  • SizeChanged is a layout-level event, fired when a layout pass completes on a control. SizeChanged is present on all controls and is fired when the control's size changes for any reason, including a Resized event in the case of a Window.