Table of Contents

Class TemplatedControl

Namespace
Avalonia.Controls.Primitives
Assembly
Avalonia.Controls.dll

A lookless control whose visual appearance is defined by its Template.

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

Constructors

TemplatedControl()

public TemplatedControl()

Fields

BackgroundProperty

Defines the Background property.

public static readonly StyledProperty<IBrush?> BackgroundProperty

Field Value

StyledProperty<IBrush>

BackgroundSizingProperty

Defines the BackgroundSizing property.

public static readonly StyledProperty<BackgroundSizing> BackgroundSizingProperty

Field Value

StyledProperty<BackgroundSizing>

BorderBrushProperty

Defines the BorderBrush property.

public static readonly StyledProperty<IBrush?> BorderBrushProperty

Field Value

StyledProperty<IBrush>

BorderThicknessProperty

Defines the BorderThickness property.

public static readonly StyledProperty<Thickness> BorderThicknessProperty

Field Value

StyledProperty<Thickness>

CornerRadiusProperty

Defines the CornerRadius property.

public static readonly StyledProperty<CornerRadius> CornerRadiusProperty

Field Value

StyledProperty<CornerRadius>

FontFamilyProperty

Defines the FontFamily property.

public static readonly StyledProperty<FontFamily> FontFamilyProperty

Field Value

StyledProperty<FontFamily>

FontFeaturesProperty

Defines the FontFeaturesProperty property.

public static readonly StyledProperty<FontFeatureCollection?> FontFeaturesProperty

Field Value

StyledProperty<FontFeatureCollection>

FontSizeProperty

Defines the FontSize property.

public static readonly StyledProperty<double> FontSizeProperty

Field Value

StyledProperty<double>

FontStretchProperty

Defines the FontWeight property.

public static readonly StyledProperty<FontStretch> FontStretchProperty

Field Value

StyledProperty<FontStretch>

FontStyleProperty

Defines the FontStyle property.

public static readonly StyledProperty<FontStyle> FontStyleProperty

Field Value

StyledProperty<FontStyle>

FontWeightProperty

Defines the FontWeight property.

public static readonly StyledProperty<FontWeight> FontWeightProperty

Field Value

StyledProperty<FontWeight>

ForegroundProperty

Defines the Foreground property.

public static readonly StyledProperty<IBrush?> ForegroundProperty

Field Value

StyledProperty<IBrush>

IsTemplateFocusTargetProperty

Defines the IsTemplateFocusTarget attached property.

public static readonly AttachedProperty<bool> IsTemplateFocusTargetProperty

Field Value

AttachedProperty<bool>

PaddingProperty

Defines the Padding property.

public static readonly StyledProperty<Thickness> PaddingProperty

Field Value

StyledProperty<Thickness>

TemplateAppliedEvent

Defines the TemplateApplied routed event.

public static readonly RoutedEvent<TemplateAppliedEventArgs> TemplateAppliedEvent

Field Value

RoutedEvent<TemplateAppliedEventArgs>

TemplateProperty

Defines the Template property.

public static readonly StyledProperty<IControlTemplate?> TemplateProperty

Field Value

StyledProperty<IControlTemplate>

Properties

Background

Gets or sets the brush used to draw the control's background.

public IBrush? Background { get; set; }

Property Value

IBrush

BackgroundSizing

Gets or sets how the control's background is drawn relative to the control's border.

public BackgroundSizing BackgroundSizing { get; set; }

Property Value

BackgroundSizing

BorderBrush

Gets or sets the brush used to draw the control's border.

public IBrush? BorderBrush { get; set; }

Property Value

IBrush

BorderThickness

Gets or sets the thickness of the control's border.

public Thickness BorderThickness { get; set; }

Property Value

Thickness

CornerRadius

Gets or sets the radius of the border rounded corners.

public CornerRadius CornerRadius { get; set; }

Property Value

CornerRadius

FontFamily

Gets or sets the font family used to draw the control's text.

public FontFamily FontFamily { get; set; }

Property Value

FontFamily

FontFeatures

Gets or sets the font features turned on/off.

public FontFeatureCollection? FontFeatures { get; set; }

Property Value

FontFeatureCollection

FontSize

Gets or sets the size of the control's text in points.

public double FontSize { get; set; }

Property Value

double

FontStretch

Gets or sets the font stretch used to draw the control's text.

public FontStretch FontStretch { get; set; }

Property Value

FontStretch

FontStyle

Gets or sets the font style used to draw the control's text.

public FontStyle FontStyle { get; set; }

Property Value

FontStyle

FontWeight

Gets or sets the font weight used to draw the control's text.

public FontWeight FontWeight { get; set; }

Property Value

FontWeight

Foreground

Gets or sets the brush used to draw the control's text and other foreground elements.

public IBrush? Foreground { get; set; }

Property Value

IBrush

Padding

Gets or sets the padding placed between the border of the control and its content.

public Thickness Padding { get; set; }

Property Value

Thickness

Template

Gets or sets the template that defines the control's appearance.

public IControlTemplate? Template { get; set; }

Property Value

IControlTemplate

Methods

ApplyTemplate()

Creates the visual children of the control, if necessary

public override sealed void ApplyTemplate()

GetIsTemplateFocusTarget(Control)

Gets the value of the IsTemplateFocusTargetProperty attached property on a control.

public static bool GetIsTemplateFocusTarget(Control control)

Parameters

control Control

The control.

Returns

bool

The property value.

GetTemplateFocusTarget()

Gets the element that receives the focus adorner.

protected override Control GetTemplateFocusTarget()

Returns

Control

The control that receives the focus adorner.

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected virtual void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is added to a rooted logical tree.

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)

Called when the styled element is removed from a rooted logical tree.

protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)

Parameters

e LogicalTreeAttachmentEventArgs

The event args.

OnTemplateChanged(AvaloniaPropertyChangedEventArgs)

Called when the Template property changes.

protected virtual void OnTemplateChanged(AvaloniaPropertyChangedEventArgs e)

Parameters

e AvaloniaPropertyChangedEventArgs

The event args.

SetIsTemplateFocusTarget(Control, bool)

Sets the value of the IsTemplateFocusTargetProperty attached property on a control.

public static void SetIsTemplateFocusTarget(Control control, bool value)

Parameters

control Control

The control.

value bool

The property value.

Remarks

When a control is navigated to using the keyboard, a focus adorner is shown - usually around the control itself. However if the TemplatedControl.IsTemplateFocusTarget attached property is set to true on an element in the control template, then the focus adorner will be shown around that control instead.

Events

TemplateApplied

Raised when the control's template is applied.

public event EventHandler<TemplateAppliedEventArgs>? TemplateApplied

Event Type

EventHandler<TemplateAppliedEventArgs>