Class Control
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
ContextMenuProperty
Defines the ContextMenu property.
public static readonly StyledProperty<ContextMenu?> ContextMenuProperty
Field Value
ContextRequestedEvent
Provides event data for the ContextRequested event.
public static readonly RoutedEvent<ContextRequestedEventArgs> ContextRequestedEvent
Field Value
FocusAdornerProperty
Defines the FocusAdorner property.
public static readonly StyledProperty<ITemplate<Control>?> FocusAdornerProperty
Field Value
LoadedEvent
Defines the Loaded event.
public static readonly RoutedEvent<RoutedEventArgs> LoadedEvent
Field Value
RequestBringIntoViewEvent
Event raised when an element wishes to be scrolled into view.
public static readonly RoutedEvent<RequestBringIntoViewEventArgs> RequestBringIntoViewEvent
Field Value
SizeChangedEvent
Defines the SizeChanged event.
public static readonly RoutedEvent<SizeChangedEventArgs> SizeChangedEvent
Field Value
TagProperty
Defines the Tag property.
public static readonly StyledProperty<object?> TagProperty
Field Value
UnloadedEvent
Defines the Unloaded event.
public static readonly RoutedEvent<RoutedEventArgs> UnloadedEvent
Field Value
Properties
ContextFlyout
Gets or sets a context flyout to the control
public FlyoutBase? ContextFlyout { get; set; }
Property Value
ContextMenu
Gets or sets a context menu to the control.
public ContextMenu? ContextMenu { get; set; }
Property Value
DataTemplates
Gets or sets the data templates for the control.
public DataTemplates DataTemplates { get; }
Property Value
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
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
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
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
VisualTreeAttachmentEventArgsThe 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
VisualTreeAttachmentEventArgsThe event args.
OnGotFocus(GotFocusEventArgs)
Called before the GotFocus event occurs.
protected override void OnGotFocus(GotFocusEventArgs e)
Parameters
e
GotFocusEventArgsThe event args.
OnKeyUp(KeyEventArgs)
Called before the KeyUp event occurs.
protected override void OnKeyUp(KeyEventArgs e)
Parameters
e
KeyEventArgsThe event args.
OnLoaded(RoutedEventArgs)
Invoked just before the Loaded event.
protected virtual void OnLoaded(RoutedEventArgs e)
Parameters
e
RoutedEventArgsThe event args.
OnLostFocus(RoutedEventArgs)
Called before the LostFocus event occurs.
protected override void OnLostFocus(RoutedEventArgs e)
Parameters
e
RoutedEventArgsThe event args.
OnPointerReleased(PointerReleasedEventArgs)
Called before the PointerReleased event occurs.
protected override void OnPointerReleased(PointerReleasedEventArgs e)
Parameters
e
PointerReleasedEventArgsThe 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.
OnSizeChanged(SizeChangedEventArgs)
Invoked just before the SizeChanged event.
protected virtual void OnSizeChanged(SizeChangedEventArgs e)
Parameters
e
SizeChangedEventArgsThe event args.
OnUnloaded(RoutedEventArgs)
Invoked just before the Unloaded event.
protected virtual void OnUnloaded(RoutedEventArgs e)
Parameters
e
RoutedEventArgsThe 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
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
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
Unloaded
Occurs when the control is removed from the visual tree.
public event EventHandler<RoutedEventArgs>? Unloaded
Event Type
Remarks
This is API symmetrical with Loaded and exists for compatibility with other XAML frameworks; however, it behaves the same as OnDetachedFromVisualTree.