Class Window
A top-level window.
public class Window : WindowBase, INotifyPropertyChanged, IDataContextProvider, IThemeVariantHost, IResourceHost, IResourceNode, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IDataTemplateHost, ISetterValue, IRenderRoot, ICloseable, IStyleHost, ILogicalRoot, ILogical, ITextInputMethodRoot, IInputRoot, IInputElement, IFocusScope, ILayoutRoot
- Inheritance
-
Window
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
Window()
Initializes a new instance of the Window class.
public Window()
Window(IWindowImpl)
Initializes a new instance of the Window class.
public Window(IWindowImpl impl)
Parameters
impl
IWindowImplThe window implementation.
Fields
CanResizeProperty
public static readonly StyledProperty<bool> CanResizeProperty
Field Value
ClosingBehaviorProperty
Defines the ClosingBehavior property.
public static readonly StyledProperty<WindowClosingBehavior> ClosingBehaviorProperty
Field Value
ExtendClientAreaChromeHintsProperty
public static readonly StyledProperty<ExtendClientAreaChromeHints> ExtendClientAreaChromeHintsProperty
Field Value
ExtendClientAreaTitleBarHeightHintProperty
public static readonly StyledProperty<double> ExtendClientAreaTitleBarHeightHintProperty
Field Value
ExtendClientAreaToDecorationsHintProperty
Defines the ExtendClientAreaToDecorationsHint property.
public static readonly StyledProperty<bool> ExtendClientAreaToDecorationsHintProperty
Field Value
IconProperty
Defines the Icon property.
public static readonly StyledProperty<WindowIcon?> IconProperty
Field Value
IsExtendedIntoWindowDecorationsProperty
Defines the IsExtendedIntoWindowDecorations property.
public static readonly DirectProperty<Window, bool> IsExtendedIntoWindowDecorationsProperty
Field Value
OffScreenMarginProperty
public static readonly DirectProperty<Window, Thickness> OffScreenMarginProperty
Field Value
ShowActivatedProperty
Defines the ShowActivated property.
public static readonly StyledProperty<bool> ShowActivatedProperty
Field Value
ShowInTaskbarProperty
Enables or disables the taskbar icon
public static readonly StyledProperty<bool> ShowInTaskbarProperty
Field Value
SizeToContentProperty
Defines the SizeToContent property.
public static readonly StyledProperty<SizeToContent> SizeToContentProperty
Field Value
SystemDecorationsProperty
Defines the SystemDecorations property.
public static readonly StyledProperty<SystemDecorations> SystemDecorationsProperty
Field Value
TitleProperty
Defines the Title property.
public static readonly StyledProperty<string?> TitleProperty
Field Value
WindowClosedEvent
Routed event that can be used for global tracking of window destruction
public static readonly RoutedEvent<RoutedEventArgs> WindowClosedEvent
Field Value
WindowDecorationMarginProperty
Defines the WindowDecorationMargin property.
public static readonly DirectProperty<Window, Thickness> WindowDecorationMarginProperty
Field Value
WindowOpenedEvent
Routed event that can be used for global tracking of opening windows
public static readonly RoutedEvent<RoutedEventArgs> WindowOpenedEvent
Field Value
WindowStartupLocationProperty
Defines the WindowStartupLocation property.
public static readonly StyledProperty<WindowStartupLocation> WindowStartupLocationProperty
Field Value
WindowStateProperty
Represents the current window state (normal, minimized, maximized)
public static readonly StyledProperty<WindowState> WindowStateProperty
Field Value
Properties
CanResize
Enables or disables resizing of the window.
public bool CanResize { get; set; }
Property Value
ClosingBehavior
Gets or sets a value indicating how the Closing event behaves in the presence of child windows.
public WindowClosingBehavior ClosingBehavior { get; set; }
Property Value
ExtendClientAreaChromeHints
Gets or Sets the ExtendClientAreaChromeHints that control how the chrome looks when the client area is extended.
public ExtendClientAreaChromeHints ExtendClientAreaChromeHints { get; set; }
Property Value
ExtendClientAreaTitleBarHeightHint
Gets or Sets the TitlebarHeightHint for when the client area is extended. A value of -1 will cause the titlebar to be auto sized to the OS default. Any other positive value will cause the titlebar to assume that height.
public double ExtendClientAreaTitleBarHeightHint { get; set; }
Property Value
ExtendClientAreaToDecorationsHint
Gets or sets if the ClientArea is Extended into the Window Decorations (chrome or border).
public bool ExtendClientAreaToDecorationsHint { get; set; }
Property Value
Icon
Gets or sets the icon of the window.
public WindowIcon? Icon { get; set; }
Property Value
IsExtendedIntoWindowDecorations
Gets if the ClientArea is Extended into the Window Decorations.
public bool IsExtendedIntoWindowDecorations { get; }
Property Value
OffScreenMargin
Gets the window margin that is hidden off the screen area. This is generally only the case on Windows when in Maximized where the window border is hidden off the screen. This Margin may be used to ensure user content doesnt overlap this space.
public Thickness OffScreenMargin { get; }
Property Value
OwnedWindows
Gets a collection of child windows owned by this window.
public IReadOnlyList<Window> OwnedWindows { get; }
Property Value
PlatformImpl
Gets the platform-specific window implementation.
public IWindowImpl? PlatformImpl { get; }
Property Value
Position
Gets or sets the window position in screen coordinates.
public PixelPoint Position { get; set; }
Property Value
ShowActivated
Gets or sets a value that indicates whether a window is activated when first shown.
public bool ShowActivated { get; set; }
Property Value
ShowInTaskbar
Enables or disables the taskbar icon
public bool ShowInTaskbar { get; set; }
Property Value
SizeToContent
Gets or sets a value indicating how the window will size itself to fit its content.
public SizeToContent SizeToContent { get; set; }
Property Value
Remarks
If SizeToContent has a value other than Manual, SizeToContent is automatically set to Manual if a user resizes the window by using the resize grip or dragging the border.
NOTE: Because of a limitation of X11, SizeToContent will be reset on X11 to Manual on any resize - including the resize that happens when the window is first shown. This is because X11 resize notifications are asynchronous and there is no way to know whether a resize came from the user or the layout system. To avoid this, consider setting CanResize to false, which will disable user resizing of the window.
StyleKeyOverride
Gets the type by which the element is styled.
protected override Type StyleKeyOverride { get; }
Property Value
Remarks
Usually controls are styled by their own type, but there are instances where you want an element to be styled by its base type, e.g. creating SpecialButton that derives from Button and adds extra functionality but is still styled as a regular Button. Override this property to change the style for a control class, returning the type that you wish the elements to be styled as.
SystemDecorations
Sets the system decorations (title bar, border, etc)
public SystemDecorations SystemDecorations { get; set; }
Property Value
Title
Gets or sets the title of the window.
public string? Title { get; set; }
Property Value
WindowDecorationMargin
Gets the WindowDecorationMargin. This tells you the thickness around the window that is used by borders and the titlebar.
public Thickness WindowDecorationMargin { get; }
Property Value
WindowStartupLocation
Gets or sets the startup location of the window.
public WindowStartupLocation WindowStartupLocation { get; set; }
Property Value
WindowState
Gets or sets the minimized/maximized state of the window.
public WindowState WindowState { get; set; }
Property Value
Methods
ArrangeSetBounds(Size)
Called during the arrange pass to set the size of the window.
protected override sealed Size ArrangeSetBounds(Size size)
Parameters
size
SizeThe requested size of the window.
Returns
- Size
The actual size of the window.
BeginMoveDrag(PointerPressedEventArgs)
Starts moving a window with left button being held. Should be called from left mouse button press event handler
public void BeginMoveDrag(PointerPressedEventArgs e)
Parameters
BeginResizeDrag(WindowEdge, PointerPressedEventArgs)
Starts resizing a window. This function is used if an application has window resizing controls. Should be called from left mouse button press event handler
public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
Parameters
Close()
Closes the window.
public void Close()
Close(object?)
Closes a dialog window with the specified result.
public void Close(object? dialogResult)
Parameters
dialogResult
objectThe dialog result.
Remarks
When the window is shown with the ShowDialog<TResult>(Window) or ShowDialog<TResult>(Window) method, the resulting task will produce the Avalonia.Controls.Window._dialogResult value when the window is closed.
ExtendClientAreaToDecorationsChanged(bool)
protected virtual void ExtendClientAreaToDecorationsChanged(bool isExtended)
Parameters
isExtended
bool
Hide()
Hides the window but does not close it.
public override void Hide()
IsVisibleChanged(AvaloniaPropertyChangedEventArgs)
protected override void IsVisibleChanged(AvaloniaPropertyChangedEventArgs e)
Parameters
MeasureOverride(Size)
Measures the control and its child elements as part of a layout pass.
protected override Size MeasureOverride(Size availableSize)
Parameters
availableSize
SizeThe size available to the control.
Returns
- Size
The desired size for the control.
OnClosing(WindowClosingEventArgs)
Raises the Closing event.
protected virtual void OnClosing(WindowClosingEventArgs e)
Parameters
e
WindowClosingEventArgsThe event args.
Remarks
A type that derives from Window may override OnClosing(WindowClosingEventArgs). The overridden method must call OnClosing(WindowClosingEventArgs) on the base class if the Closing event needs to be raised.
OnCreateAutomationPeer()
Returns a new, type-specific AutomationPeer implementation for the control.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer
The type-specific AutomationPeer implementation.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
Show()
Shows the window.
public override void Show()
Exceptions
- InvalidOperationException
The window has already been closed.
Show(Window)
Shows the window as a child of owner
.
public void Show(Window owner)
Parameters
owner
WindowWindow that will be the owner of the shown window.
Exceptions
- InvalidOperationException
The window has already been closed.
ShowDialog(Window)
Shows the window as a dialog.
public Task ShowDialog(Window owner)
Parameters
owner
WindowThe dialog's owner window.
Returns
- Task
A task that can be used to track the lifetime of the dialog.
Exceptions
- InvalidOperationException
The window has already been closed.
ShowDialog<TResult>(Window)
Shows the window as a dialog.
public Task<TResult> ShowDialog<TResult>(Window owner)
Parameters
owner
WindowThe dialog's owner window.
Returns
- Task<TResult>
. A task that can be used to retrieve the result of the dialog when it closes.
Type Parameters
TResult
The type of the result produced by the dialog.
SortWindowsByZOrder(Window[])
Sorts the windows ascending by their Z order - the topmost window will be the last in the list.
public static void SortWindowsByZOrder(Window[] windows)
Parameters
windows
Window[]
Events
Closing
Fired before a window is closed.
public event EventHandler<WindowClosingEventArgs>? Closing