Class WindowBase
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
IWindowBaseImpldependencyResolver
IAvaloniaDependencyResolver
Fields
IsActiveProperty
Defines the IsActive property.
public static readonly DirectProperty<WindowBase, bool> IsActiveProperty
Field Value
OwnerProperty
Defines the Owner property.
public static readonly DirectProperty<WindowBase, WindowBase?> OwnerProperty
Field Value
TopmostProperty
public static readonly StyledProperty<bool> TopmostProperty
Field Value
Properties
DesktopScaling
Gets the scaling factor for Window positioning and sizing.
public double DesktopScaling { get; }
Property Value
IgnoreVisibilityChanges
protected bool IgnoreVisibilityChanges { get; }
Property Value
IsActive
Gets a value that indicates whether the window is active.
public bool IsActive { get; }
Property Value
Owner
Gets or sets the owner of the window.
public WindowBase? Owner { get; protected set; }
Property Value
PlatformImpl
public IWindowBaseImpl? PlatformImpl { get; }
Property Value
Screens
Gets platform screens implementation.
public Screens Screens { get; }
Property Value
Topmost
Gets or sets whether this window appears on top of all other windows
public bool Topmost { get; set; }
Property Value
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
RectThe 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
SizeThe 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
MeasureCore(Size)
Overrides the core measure logic for windows.
protected override Size MeasureCore(Size availableSize)
Parameters
availableSize
SizeThe 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
EventArgsThe event args.
OnOpened(EventArgs)
Raises the Opened event.
protected override void OnOpened(EventArgs e)
Parameters
e
EventArgsThe event args.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
OnResized(WindowResizedEventArgs)
Raises the Resized event.
protected virtual void OnResized(WindowResizedEventArgs e)
Parameters
e
WindowResizedEventArgsAn 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
Deactivated
Fired when the window is deactivated.
public event EventHandler? Deactivated
Event Type
PositionChanged
Fired when the window position is changed.
public event EventHandler<PixelPointEventArgs>? PositionChanged
Event Type
Resized
Occurs when the window is resized.
public event EventHandler<WindowResizedEventArgs>? Resized
Event Type
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.