Table of Contents

Class TextPresenter

Namespace
Avalonia.Controls.Presenters
Assembly
Avalonia.Controls.dll
public class TextPresenter : Control, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
TextPresenter
Implements
Inherited Members
Extension Methods

Constructors

TextPresenter()

public TextPresenter()

Fields

BackgroundProperty

Defines the Background property.

public static readonly StyledProperty<IBrush?> BackgroundProperty

Field Value

StyledProperty<IBrush>

CaretBlinkIntervalProperty

public static readonly StyledProperty<TimeSpan> CaretBlinkIntervalProperty

Field Value

StyledProperty<TimeSpan>

CaretBrushProperty

public static readonly StyledProperty<IBrush?> CaretBrushProperty

Field Value

StyledProperty<IBrush>

CaretIndexProperty

public static readonly StyledProperty<int> CaretIndexProperty

Field Value

StyledProperty<int>

LetterSpacingProperty

Defines the LetterSpacing property.

public static readonly StyledProperty<double> LetterSpacingProperty

Field Value

StyledProperty<double>

LineHeightProperty

Defines the LineHeight property.

public static readonly StyledProperty<double> LineHeightProperty

Field Value

StyledProperty<double>

PasswordCharProperty

public static readonly StyledProperty<char> PasswordCharProperty

Field Value

StyledProperty<char>

PreeditTextCursorPositionProperty

Defines the PreeditText property.

public static readonly StyledProperty<int?> PreeditTextCursorPositionProperty

Field Value

StyledProperty<int?>

PreeditTextProperty

Defines the PreeditText property.

public static readonly StyledProperty<string?> PreeditTextProperty

Field Value

StyledProperty<string>

RevealPasswordProperty

public static readonly StyledProperty<bool> RevealPasswordProperty

Field Value

StyledProperty<bool>

SelectionBrushProperty

public static readonly StyledProperty<IBrush?> SelectionBrushProperty

Field Value

StyledProperty<IBrush>

SelectionEndProperty

public static readonly StyledProperty<int> SelectionEndProperty

Field Value

StyledProperty<int>

SelectionForegroundBrushProperty

public static readonly StyledProperty<IBrush?> SelectionForegroundBrushProperty

Field Value

StyledProperty<IBrush>

SelectionStartProperty

public static readonly StyledProperty<int> SelectionStartProperty

Field Value

StyledProperty<int>

ShowSelectionHighlightProperty

public static readonly StyledProperty<bool> ShowSelectionHighlightProperty

Field Value

StyledProperty<bool>

TextAlignmentProperty

Defines the TextAlignment property.

public static readonly StyledProperty<TextAlignment> TextAlignmentProperty

Field Value

StyledProperty<TextAlignment>

TextProperty

Defines the Text property.

public static readonly StyledProperty<string?> TextProperty

Field Value

StyledProperty<string>

TextWrappingProperty

Defines the TextWrapping property.

public static readonly StyledProperty<TextWrapping> TextWrappingProperty

Field Value

StyledProperty<TextWrapping>

Properties

Background

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

public IBrush? Background { get; set; }

Property Value

IBrush

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.

CaretBlinkInterval

Gets or sets the caret blink rate

public TimeSpan CaretBlinkInterval { get; set; }

Property Value

TimeSpan

CaretBrush

public IBrush? CaretBrush { get; set; }

Property Value

IBrush

CaretIndex

public int CaretIndex { get; set; }

Property Value

int

FontFamily

Gets or sets the font family.

public FontFamily FontFamily { get; set; }

Property Value

FontFamily

FontFeatures

Gets or sets the font family.

public FontFeatureCollection? FontFeatures { get; set; }

Property Value

FontFeatureCollection

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

LetterSpacing

Gets or sets the letter spacing.

public double LetterSpacing { get; set; }

Property Value

double

LineHeight

Gets or sets the line height. By default, this is set to NaN, which determines the appropriate height automatically.

public double LineHeight { get; set; }

Property Value

double

PasswordChar

public char PasswordChar { get; set; }

Property Value

char

PreeditText

public string? PreeditText { get; set; }

Property Value

string

PreeditTextCursorPosition

public int? PreeditTextCursorPosition { get; set; }

Property Value

int?

RevealPassword

public bool RevealPassword { get; set; }

Property Value

bool

SelectionBrush

public IBrush? SelectionBrush { get; set; }

Property Value

IBrush

SelectionEnd

public int SelectionEnd { get; set; }

Property Value

int

SelectionForegroundBrush

public IBrush? SelectionForegroundBrush { get; set; }

Property Value

IBrush

SelectionStart

public int SelectionStart { get; set; }

Property Value

int

ShowSelectionHighlight

Gets or sets a value that determines whether the TextPresenter shows a selection highlight.

public bool ShowSelectionHighlight { get; set; }

Property Value

bool

Text

Gets or sets the text.

[Content]
public string? Text { get; set; }

Property Value

string

TextAlignment

Gets or sets the text alignment.

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

TextLayout

Gets the TextLayout used to render the text.

public TextLayout TextLayout { get; }

Property Value

TextLayout

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()

Creates the TextLayout used to render the text.

protected virtual TextLayout CreateTextLayout()

Returns

TextLayout

A TextLayout object.

GetNextCharacterHit(LogicalDirection)

public CharacterHit GetNextCharacterHit(LogicalDirection direction = LogicalDirection.Forward)

Parameters

direction LogicalDirection

Returns

CharacterHit

HideCaret()

public void HideCaret()

InvalidateTextLayout()

protected virtual 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.

MoveCaretHorizontal(LogicalDirection)

public void MoveCaretHorizontal(LogicalDirection direction = LogicalDirection.Forward)

Parameters

direction LogicalDirection

MoveCaretToPoint(Point)

public void MoveCaretToPoint(Point point)

Parameters

point Point

MoveCaretToTextPosition(int, bool)

public void MoveCaretToTextPosition(int textPosition, bool trailingEdge = false)

Parameters

textPosition int
trailingEdge bool

MoveCaretVertical(LogicalDirection)

public void MoveCaretVertical(LogicalDirection direction = LogicalDirection.Forward)

Parameters

direction LogicalDirection

OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is added to a rooted visual tree.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is removed from a rooted visual tree.

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

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.

ShowCaret()

public void ShowCaret()

Events

CaretBoundsChanged

public event EventHandler? CaretBoundsChanged

Event Type

EventHandler