Table of Contents

Class TextBlock

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

A control that displays a block of text.

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

Constructors

TextBlock()

public TextBlock()

Fields

BackgroundProperty

Defines the Background property.

public static readonly StyledProperty<IBrush?> BackgroundProperty

Field Value

StyledProperty<IBrush>

BaselineOffsetProperty

DependencyProperty for BaselineOffset property.

public static readonly AttachedProperty<double> BaselineOffsetProperty

Field Value

AttachedProperty<double>

FontFamilyProperty

Defines the FontFamily property.

public static readonly StyledProperty<FontFamily> FontFamilyProperty

Field Value

StyledProperty<FontFamily>

FontFeaturesProperty

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

InlinesProperty

Defines the Inlines property.

public static readonly DirectProperty<TextBlock, InlineCollection?> InlinesProperty

Field Value

DirectProperty<TextBlock, InlineCollection>

LetterSpacingProperty

Defines the LetterSpacing property.

public static readonly AttachedProperty<double> LetterSpacingProperty

Field Value

AttachedProperty<double>

LineHeightProperty

Defines the LineHeight property.

public static readonly AttachedProperty<double> LineHeightProperty

Field Value

AttachedProperty<double>

LineSpacingProperty

Defines the LineSpacing property.

public static readonly AttachedProperty<double> LineSpacingProperty

Field Value

AttachedProperty<double>

MaxLinesProperty

Defines the MaxLines property.

public static readonly AttachedProperty<int> MaxLinesProperty

Field Value

AttachedProperty<int>

PaddingProperty

Defines the Padding property.

public static readonly StyledProperty<Thickness> PaddingProperty

Field Value

StyledProperty<Thickness>

TextAlignmentProperty

Defines the TextAlignment property.

public static readonly AttachedProperty<TextAlignment> TextAlignmentProperty

Field Value

AttachedProperty<TextAlignment>

TextDecorationsProperty

Defines the TextDecorations property.

public static readonly StyledProperty<TextDecorationCollection?> TextDecorationsProperty

Field Value

StyledProperty<TextDecorationCollection>

TextProperty

Defines the Text property.

public static readonly StyledProperty<string?> TextProperty

Field Value

StyledProperty<string>

TextTrimmingProperty

Defines the TextTrimming property.

public static readonly AttachedProperty<TextTrimming> TextTrimmingProperty

Field Value

AttachedProperty<TextTrimming>

TextWrappingProperty

Defines the TextWrapping property.

public static readonly AttachedProperty<TextWrapping> TextWrappingProperty

Field Value

AttachedProperty<TextWrapping>

_constraint

protected Size _constraint

Field Value

Size

_textRuns

protected IReadOnlyList<TextRun>? _textRuns

Field Value

IReadOnlyList<TextRun>

Properties

Background

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

public IBrush? Background { get; set; }

Property Value

IBrush

BaselineOffset

The BaselineOffset property provides an adjustment to baseline offset

public double BaselineOffset { get; set; }

Property Value

double

BypassFlowDirectionPolicies

Gets a value indicating whether control bypass FlowDirecton policies.

protected override bool BypassFlowDirectionPolicies { get; }

Property Value

bool

Remarks

Related to FlowDirection system and returns false as default, so if FlowDirection is RTL then control will get a mirror presentation. For controls that want to avoid this behavior, override this property and return true.

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.

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

Inlines

Gets or sets the inlines.

[Content]
public InlineCollection? Inlines { get; set; }

Property Value

InlineCollection

LetterSpacing

Gets or sets the letter spacing.

public double LetterSpacing { get; set; }

Property Value

double

LineHeight

Gets or sets the height of each line of content.

public double LineHeight { get; set; }

Property Value

double

LineSpacing

Gets or sets the extra distance of each line to the next line.

public double LineSpacing { get; set; }

Property Value

double

MaxLines

Gets or sets the maximum number of text lines.

public int MaxLines { get; set; }

Property Value

int

Padding

Gets or sets the padding to place around the Text.

public Thickness Padding { get; set; }

Property Value

Thickness

Text

Gets or sets the text.

public string? Text { get; set; }

Property Value

string

TextAlignment

Gets or sets the text alignment.

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

TextDecorations

Gets or sets the text decorations.

public TextDecorationCollection? TextDecorations { get; set; }

Property Value

TextDecorationCollection

TextLayout

Gets the TextLayout used to render the text.

public TextLayout TextLayout { get; }

Property Value

TextLayout

TextTrimming

Gets or sets the control's text trimming mode.

public TextTrimming TextTrimming { get; set; }

Property Value

TextTrimming

TextWrapping

Gets or sets the control's text wrapping mode.

public TextWrapping TextWrapping { get; set; }

Property Value

TextWrapping

Methods

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.

CreateTextLayout(string?)

Creates the TextLayout used to render the text.

protected virtual TextLayout CreateTextLayout(string? text)

Parameters

text string

Returns

TextLayout

A TextLayout object.

GetBaselineOffset(Control)

Reads the attached property from the given element

public static double GetBaselineOffset(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

double

GetLetterSpacing(Control)

Reads the attached property from the given element

public static double GetLetterSpacing(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

double

GetLineHeight(Control)

Reads the attached property from the given element

public static double GetLineHeight(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

double

GetMaxLines(Control)

Reads the attached property from the given element

public static int GetMaxLines(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

int

GetTextAlignment(Control)

Reads the attached property from the given element

public static TextAlignment GetTextAlignment(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

TextAlignment

GetTextTrimming(Control)

Reads the attached property from the given element

public static TextTrimming GetTextTrimming(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

TextTrimming

GetTextWrapping(Control)

Reads the attached property from the given element

public static TextWrapping GetTextWrapping(Control control)

Parameters

control Control

The element to which to read the attached property.

Returns

TextWrapping

InvalidateTextLayout()

Invalidates TextLayout.

protected void InvalidateTextLayout()

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.

OnCreateAutomationPeer()

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

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer

The type-specific AutomationPeer implementation.

OnMeasureInvalidated()

Called by InvalidateMeasure

protected override void OnMeasureInvalidated()

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 TextBlock to a drawing context.

public override sealed void Render(DrawingContext context)

Parameters

context DrawingContext

The drawing context.

RenderTextLayout(DrawingContext, Point)

protected virtual void RenderTextLayout(DrawingContext context, Point origin)

Parameters

context DrawingContext
origin Point

SetBaselineOffset(Control, double)

Writes the attached property BaselineOffset to the given element.

public static void SetBaselineOffset(Control control, double value)

Parameters

control Control

The element to which to write the attached property.

value double

The property value to set

SetLetterSpacing(Control, double)

Writes the attached property LetterSpacing to the given element.

public static void SetLetterSpacing(Control control, double letterSpacing)

Parameters

control Control

The element to which to write the attached property.

letterSpacing double

The property value to set

SetLineHeight(Control, double)

Writes the attached property BaselineOffset to the given element.

public static void SetLineHeight(Control control, double height)

Parameters

control Control

The element to which to write the attached property.

height double

The property value to set

SetMaxLines(Control, int)

Writes the attached property BaselineOffset to the given element.

public static void SetMaxLines(Control control, int maxLines)

Parameters

control Control

The element to which to write the attached property.

maxLines int

The property value to set

SetTextAlignment(Control, TextAlignment)

Writes the attached property BaselineOffset to the given element.

public static void SetTextAlignment(Control control, TextAlignment alignment)

Parameters

control Control

The element to which to write the attached property.

alignment TextAlignment

The property value to set

SetTextTrimming(Control, TextTrimming)

Writes the attached property BaselineOffset to the given element.

public static void SetTextTrimming(Control control, TextTrimming trimming)

Parameters

control Control

The element to which to write the attached property.

trimming TextTrimming

The property value to set

SetTextWrapping(Control, TextWrapping)

Writes the attached property BaselineOffset to the given element.

public static void SetTextWrapping(Control control, TextWrapping wrapping)

Parameters

control Control

The element to which to write the attached property.

wrapping TextWrapping

The property value to set