Class TextBlock
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
BaselineOffsetProperty
DependencyProperty for BaselineOffset property.
public static readonly AttachedProperty<double> BaselineOffsetProperty
Field Value
FontFamilyProperty
Defines the FontFamily property.
public static readonly StyledProperty<FontFamily> FontFamilyProperty
Field Value
FontFeaturesProperty
Defines the FontFeatures property.
public static readonly StyledProperty<FontFeatureCollection?> FontFeaturesProperty
Field Value
FontSizeProperty
Defines the FontSize property.
public static readonly StyledProperty<double> FontSizeProperty
Field Value
FontStretchProperty
Defines the FontStretch property.
public static readonly StyledProperty<FontStretch> FontStretchProperty
Field Value
FontStyleProperty
Defines the FontStyle property.
public static readonly StyledProperty<FontStyle> FontStyleProperty
Field Value
FontWeightProperty
Defines the FontWeight property.
public static readonly StyledProperty<FontWeight> FontWeightProperty
Field Value
ForegroundProperty
Defines the Foreground property.
public static readonly StyledProperty<IBrush?> ForegroundProperty
Field Value
InlinesProperty
Defines the Inlines property.
public static readonly DirectProperty<TextBlock, InlineCollection?> InlinesProperty
Field Value
LetterSpacingProperty
Defines the LetterSpacing property.
public static readonly AttachedProperty<double> LetterSpacingProperty
Field Value
LineHeightProperty
Defines the LineHeight property.
public static readonly AttachedProperty<double> LineHeightProperty
Field Value
LineSpacingProperty
Defines the LineSpacing property.
public static readonly AttachedProperty<double> LineSpacingProperty
Field Value
MaxLinesProperty
Defines the MaxLines property.
public static readonly AttachedProperty<int> MaxLinesProperty
Field Value
PaddingProperty
Defines the Padding property.
public static readonly StyledProperty<Thickness> PaddingProperty
Field Value
TextAlignmentProperty
Defines the TextAlignment property.
public static readonly AttachedProperty<TextAlignment> TextAlignmentProperty
Field Value
TextDecorationsProperty
Defines the TextDecorations property.
public static readonly StyledProperty<TextDecorationCollection?> TextDecorationsProperty
Field Value
TextProperty
Defines the Text property.
public static readonly StyledProperty<string?> TextProperty
Field Value
TextTrimmingProperty
Defines the TextTrimming property.
public static readonly AttachedProperty<TextTrimming> TextTrimmingProperty
Field Value
TextWrappingProperty
Defines the TextWrapping property.
public static readonly AttachedProperty<TextWrapping> TextWrappingProperty
Field Value
_constraint
protected Size _constraint
Field Value
_textRuns
protected IReadOnlyList<TextRun>? _textRuns
Field Value
Properties
Background
Gets or sets a brush used to paint the control's background.
public IBrush? Background { get; set; }
Property Value
BaselineOffset
The BaselineOffset property provides an adjustment to baseline offset
public double BaselineOffset { get; set; }
Property Value
BypassFlowDirectionPolicies
Gets a value indicating whether control bypass FlowDirecton policies.
protected override bool BypassFlowDirectionPolicies { get; }
Property Value
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
FontFeatures
Gets or sets the font features.
public FontFeatureCollection? FontFeatures { get; set; }
Property Value
FontSize
Gets or sets the size of the control's text in points.
public double FontSize { get; set; }
Property Value
FontStretch
Gets or sets the font stretch used to draw the control's text.
public FontStretch FontStretch { get; set; }
Property Value
FontStyle
Gets or sets the font style used to draw the control's text.
public FontStyle FontStyle { get; set; }
Property Value
FontWeight
Gets or sets the font weight used to draw the control's text.
public FontWeight FontWeight { get; set; }
Property Value
Foreground
Gets or sets the brush used to draw the control's text and other foreground elements.
public IBrush? Foreground { get; set; }
Property Value
Inlines
Gets or sets the inlines.
[Content]
public InlineCollection? Inlines { get; set; }
Property Value
LetterSpacing
Gets or sets the letter spacing.
public double LetterSpacing { get; set; }
Property Value
LineHeight
Gets or sets the height of each line of content.
public double LineHeight { get; set; }
Property Value
LineSpacing
Gets or sets the extra distance of each line to the next line.
public double LineSpacing { get; set; }
Property Value
MaxLines
Gets or sets the maximum number of text lines.
public int MaxLines { get; set; }
Property Value
Padding
Gets or sets the padding to place around the Text.
public Thickness Padding { get; set; }
Property Value
Text
Gets or sets the text.
public string? Text { get; set; }
Property Value
TextAlignment
Gets or sets the text alignment.
public TextAlignment TextAlignment { get; set; }
Property Value
TextDecorations
Gets or sets the text decorations.
public TextDecorationCollection? TextDecorations { get; set; }
Property Value
TextLayout
Gets the TextLayout used to render the text.
public TextLayout TextLayout { get; }
Property Value
TextTrimming
Gets or sets the control's text trimming mode.
public TextTrimming TextTrimming { get; set; }
Property Value
TextWrapping
Gets or sets the control's text wrapping mode.
public TextWrapping TextWrapping { get; set; }
Property Value
Methods
ArrangeOverride(Size)
Positions child elements as part of a layout pass.
protected override Size ArrangeOverride(Size finalSize)
Parameters
finalSize
SizeThe 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
ControlThe element to which to read the attached property.
Returns
GetLetterSpacing(Control)
Reads the attached property from the given element
public static double GetLetterSpacing(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
GetLineHeight(Control)
Reads the attached property from the given element
public static double GetLineHeight(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
GetMaxLines(Control)
Reads the attached property from the given element
public static int GetMaxLines(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
GetTextAlignment(Control)
Reads the attached property from the given element
public static TextAlignment GetTextAlignment(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
GetTextTrimming(Control)
Reads the attached property from the given element
public static TextTrimming GetTextTrimming(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
GetTextWrapping(Control)
Reads the attached property from the given element
public static TextWrapping GetTextWrapping(Control control)
Parameters
control
ControlThe element to which to read the attached property.
Returns
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
SizeThe 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
AvaloniaPropertyChangedEventArgsThe property change details.
Render(DrawingContext)
Renders the TextBlock to a drawing context.
public override sealed void Render(DrawingContext context)
Parameters
context
DrawingContextThe drawing context.
RenderTextLayout(DrawingContext, Point)
protected virtual void RenderTextLayout(DrawingContext context, Point origin)
Parameters
context
DrawingContextorigin
Point
SetBaselineOffset(Control, double)
Writes the attached property BaselineOffset to the given element.
public static void SetBaselineOffset(Control control, double value)
Parameters
control
ControlThe element to which to write the attached property.
value
doubleThe 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
ControlThe element to which to write the attached property.
letterSpacing
doubleThe 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
ControlThe element to which to write the attached property.
height
doubleThe 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
ControlThe element to which to write the attached property.
maxLines
intThe 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
ControlThe element to which to write the attached property.
alignment
TextAlignmentThe 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
ControlThe element to which to write the attached property.
trimming
TextTrimmingThe 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
ControlThe element to which to write the attached property.
wrapping
TextWrappingThe property value to set