Table of Contents

Class ContentPresenter

Namespace
Avalonia.Controls.Presenters
Assembly
Avalonia.Controls.dll

Presents a single item of data inside a TemplatedControl template.

[PseudoClasses(new string[] { ":empty" })]
public class ContentPresenter : Control, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
ContentPresenter
Implements
Derived
Inherited Members
Extension Methods

Constructors

ContentPresenter()

public ContentPresenter()

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>

BoxShadowProperty

Defines the BoxShadow property.

public static readonly StyledProperty<BoxShadows> BoxShadowProperty

Field Value

StyledProperty<BoxShadows>

ChildProperty

Defines the Child property.

public static readonly DirectProperty<ContentPresenter, Control?> ChildProperty

Field Value

DirectProperty<ContentPresenter, Control>

ContentProperty

Defines the Content property.

public static readonly StyledProperty<object?> ContentProperty

Field Value

StyledProperty<object>

ContentTemplateProperty

Defines the ContentTemplate property.

public static readonly StyledProperty<IDataTemplate?> ContentTemplateProperty

Field Value

StyledProperty<IDataTemplate>

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>

FontSizeProperty

Defines the FontSize property.

public static readonly StyledProperty<double> FontSizeProperty

Field Value

StyledProperty<double>

FontStretchProperty

Defines the FontStretch 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>

HorizontalContentAlignmentProperty

Defines the HorizontalContentAlignment property.

public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty

Field Value

StyledProperty<HorizontalAlignment>

LineHeightProperty

Defines the LineHeight property

public static readonly StyledProperty<double> LineHeightProperty

Field Value

StyledProperty<double>

MaxLinesProperty

Defines the MaxLines property

public static readonly StyledProperty<int> MaxLinesProperty

Field Value

StyledProperty<int>

PaddingProperty

Defines the Padding property.

public static readonly StyledProperty<Thickness> PaddingProperty

Field Value

StyledProperty<Thickness>

RecognizesAccessKeyProperty

Defines the RecognizesAccessKey property

public static readonly StyledProperty<bool> RecognizesAccessKeyProperty

Field Value

StyledProperty<bool>

TextAlignmentProperty

Defines the TextAlignment property

public static readonly StyledProperty<TextAlignment> TextAlignmentProperty

Field Value

StyledProperty<TextAlignment>

TextTrimmingProperty

Defines the TextTrimming property

public static readonly StyledProperty<TextTrimming> TextTrimmingProperty

Field Value

StyledProperty<TextTrimming>

TextWrappingProperty

Defines the TextWrapping property

public static readonly StyledProperty<TextWrapping> TextWrappingProperty

Field Value

StyledProperty<TextWrapping>

VerticalContentAlignmentProperty

Defines the VerticalContentAlignment property.

public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty

Field Value

StyledProperty<VerticalAlignment>

Properties

Background

Gets or sets a brush with which to paint the background.

public IBrush? Background { get; set; }

Property Value

IBrush

BackgroundSizing

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

public BackgroundSizing BackgroundSizing { get; set; }

Property Value

BackgroundSizing

BorderBrush

Gets or sets a brush with which to paint the border.

public IBrush? BorderBrush { get; set; }

Property Value

IBrush

BorderThickness

Gets or sets the thickness of the border.

public Thickness BorderThickness { get; set; }

Property Value

Thickness

BoxShadow

Gets or sets the box shadow effect parameters

public BoxShadows BoxShadow { get; set; }

Property Value

BoxShadows

Child

Gets the control displayed by the presenter.

public Control? Child { get; }

Property Value

Control

Content

Gets or sets the content to be displayed by the presenter.

[DependsOn("ContentTemplate")]
public object? Content { get; set; }

Property Value

object

ContentTemplate

Gets or sets the data template used to display the content of the control.

public IDataTemplate? ContentTemplate { get; set; }

Property Value

IDataTemplate

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.

public FontFamily FontFamily { get; set; }

Property Value

FontFamily

FontSize

Gets or sets the font size.

public double FontSize { get; set; }

Property Value

double

FontStretch

Gets or sets the font stretch.

public FontStretch FontStretch { get; set; }

Property Value

FontStretch

FontStyle

Gets or sets the font style.

public FontStyle FontStyle { get; set; }

Property Value

FontStyle

FontWeight

Gets or sets the font weight.

public FontWeight FontWeight { get; set; }

Property Value

FontWeight

Foreground

Gets or sets a brush used to paint the text.

public IBrush? Foreground { get; set; }

Property Value

IBrush

HorizontalContentAlignment

Gets or sets the horizontal alignment of the content within the border the control.

public HorizontalAlignment HorizontalContentAlignment { get; set; }

Property Value

HorizontalAlignment

LineHeight

Gets or sets the line height

public double LineHeight { get; set; }

Property Value

double

MaxLines

Gets or sets the max lines

public int MaxLines { get; set; }

Property Value

int

Padding

Gets or sets the space between the border and the Child control.

public Thickness Padding { get; set; }

Property Value

Thickness

RecognizesAccessKey

Determine if ContentPresenter should use AccessText in its style

public bool RecognizesAccessKey { get; set; }

Property Value

bool

TextAlignment

Gets or sets the text alignment

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

TextTrimming

Gets or sets the text trimming

public TextTrimming TextTrimming { get; set; }

Property Value

TextTrimming

TextWrapping

Gets or sets the text wrapping

public TextWrapping TextWrapping { get; set; }

Property Value

TextWrapping

VerticalContentAlignment

Gets or sets the vertical alignment of the content within the border of the control.

public VerticalAlignment VerticalContentAlignment { get; set; }

Property Value

VerticalAlignment

Methods

ApplyTemplate()

Creates the visual children of the control, if necessary

public override sealed void ApplyTemplate()

ArrangeOverride(Size)

Positions child elements as part of a layout pass.

protected override Size ArrangeOverride(Size finalSize)

Parameters

finalSize Size

The size available to the control.

Returns

Size

The actual size used.

MeasureOverride(Size)

Measures the control and its child elements as part of a layout pass.

protected override Size MeasureOverride(Size availableSize)

Parameters

availableSize Size

The size available to the control.

Returns

Size

The desired size for the control.

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.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

Render(DrawingContext)

Renders the visual to a DrawingContext.

public override sealed void Render(DrawingContext context)

Parameters

context DrawingContext

The drawing context.

UpdateChild()

Updates the Child control based on the control's Content.

public void UpdateChild()

Remarks

Usually the Child control is created automatically when ApplyTemplate() is called; however for this to happen, the control needs to be attached to a logical tree (if the control is not attached to the logical tree, it is reasonable to expect that the DataTemplates needed for the child are not yet available). This method forces the Child control's creation at any point, and is particularly useful in unit tests.