Table of Contents

Class Control

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Base class for Avalonia controls.

public class Control : InputElement, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
Control
Implements
Derived
Inherited Members
Extension Methods

Remarks

The control class extends InputElement and adds the following features:

  • A Tag property to allow user-defined data to be attached to the control.
  • ContextRequestedEvent and other context menu related members.

Constructors

Control()

public Control()

Fields

ContextFlyoutProperty

Defines the ContextFlyout property

public static readonly StyledProperty<FlyoutBase?> ContextFlyoutProperty

Field Value

StyledProperty<FlyoutBase>

ContextMenuProperty

Defines the ContextMenu property.

public static readonly StyledProperty<ContextMenu?> ContextMenuProperty

Field Value

StyledProperty<ContextMenu>

ContextRequestedEvent

Provides event data for the ContextRequested event.

public static readonly RoutedEvent<ContextRequestedEventArgs> ContextRequestedEvent

Field Value

RoutedEvent<ContextRequestedEventArgs>

FocusAdornerProperty

Defines the FocusAdorner property.

public static readonly StyledProperty<ITemplate<Control>?> FocusAdornerProperty

Field Value

StyledProperty<ITemplate<Control>>

LoadedEvent

Defines the Loaded event.

public static readonly RoutedEvent<RoutedEventArgs> LoadedEvent

Field Value

RoutedEvent<RoutedEventArgs>

RequestBringIntoViewEvent

Event raised when an element wishes to be scrolled into view.

public static readonly RoutedEvent<RequestBringIntoViewEventArgs> RequestBringIntoViewEvent

Field Value

RoutedEvent<RequestBringIntoViewEventArgs>

SizeChangedEvent

Defines the SizeChanged event.

public static readonly RoutedEvent<SizeChangedEventArgs> SizeChangedEvent

Field Value

RoutedEvent<SizeChangedEventArgs>

TagProperty

Defines the Tag property.

public static readonly StyledProperty<object?> TagProperty

Field Value

StyledProperty<object>

UnloadedEvent

Defines the Unloaded event.

public static readonly RoutedEvent<RoutedEventArgs> UnloadedEvent

Field Value

RoutedEvent<RoutedEventArgs>

Properties

ContextFlyout

Gets or sets a context flyout to the control

public FlyoutBase? ContextFlyout { get; set; }

Property Value

FlyoutBase

ContextMenu

Gets or sets a context menu to the control.

public ContextMenu? ContextMenu { get; set; }

Property Value

ContextMenu

DataTemplates

Gets or sets the data templates for the control.

public DataTemplates DataTemplates { get; }

Property Value

DataTemplates

Remarks

Each control may define data templates which are applied to the control itself and its children.

FocusAdorner

Gets or sets the control's focus adorner.

public ITemplate<Control>? FocusAdorner { get; set; }

Property Value

ITemplate<Control>

IsLoaded

Gets a value indicating whether the control is fully constructed in the visual tree and both layout and render are complete.

public bool IsLoaded { get; }

Property Value

bool

Remarks

This is set to true while raising the Loaded event.

Tag

Gets or sets a user-defined object attached to the control.

public object? Tag { get; set; }

Property Value

object

Methods

GetTemplateFocusTarget()

Gets the element that receives the focus adorner.

protected virtual Control? GetTemplateFocusTarget()

Returns

Control

The control that receives the focus adorner.

OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs)

Calls the OnAttachedToVisualTree(VisualTreeAttachmentEventArgs) method for this control and all of its visual descendants.

protected override sealed void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnCreateAutomationPeer()

Returns a new, type-specific AutomationPeer implementation for the control.

protected virtual AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs)

Calls the OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs) method for this control and all of its visual descendants.

protected override sealed void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnGotFocus(GotFocusEventArgs)

Called before the GotFocus event occurs.

protected override void OnGotFocus(GotFocusEventArgs e)

Parameters

e GotFocusEventArgs

The event args.

OnKeyUp(KeyEventArgs)

Called before the KeyUp event occurs.

protected override void OnKeyUp(KeyEventArgs e)

Parameters

e KeyEventArgs

The event args.

OnLoaded(RoutedEventArgs)

Invoked just before the Loaded event.

protected virtual void OnLoaded(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

OnLostFocus(RoutedEventArgs)

Called before the LostFocus event occurs.

protected override void OnLostFocus(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

OnPointerReleased(PointerReleasedEventArgs)

Called before the PointerReleased event occurs.

protected override void OnPointerReleased(PointerReleasedEventArgs e)

Parameters

e PointerReleasedEventArgs

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.

OnSizeChanged(SizeChangedEventArgs)

Invoked just before the SizeChanged event.

protected virtual void OnSizeChanged(SizeChangedEventArgs e)

Parameters

e SizeChangedEventArgs

The event args.

OnUnloaded(RoutedEventArgs)

Invoked just before the Unloaded event.

protected virtual void OnUnloaded(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

Events

ContextRequested

Occurs when the user has completed a context input gesture, such as a right-click.

public event EventHandler<ContextRequestedEventArgs>? ContextRequested

Event Type

EventHandler<ContextRequestedEventArgs>

Loaded

Occurs when the control has been fully constructed in the visual tree and both layout and render are complete.

public event EventHandler<RoutedEventArgs>? Loaded

Event Type

EventHandler<RoutedEventArgs>

Remarks

This event is guaranteed to occur after the control template is applied and references to objects created after the template is applied are available. This makes it different from OnAttachedToVisualTree which doesn't have these references. This event occurs at the latest possible time in the control creation life-cycle.

SizeChanged

Occurs when the bounds (actual size) of the control have changed.

public event EventHandler<SizeChangedEventArgs>? SizeChanged

Event Type

EventHandler<SizeChangedEventArgs>

Unloaded

Occurs when the control is removed from the visual tree.

public event EventHandler<RoutedEventArgs>? Unloaded

Event Type

EventHandler<RoutedEventArgs>

Remarks

This is API symmetrical with Loaded and exists for compatibility with other XAML frameworks; however, it behaves the same as OnDetachedFromVisualTree.