TextBlock
Description
TextBlock is a display component used to render text in a consistent and customizable manner. It is part of the Components group and is useful for presenting static or dynamic text content in your web applications. By leveraging its fluent API, you can easily adjust text size, weight, alignment, color variants, wrapping behavior, and more.
Usage
Instantiate a TextBlock using the Tesserae.UI helper method. You can pass the desired text along with optional parameters to control HTML parsing, selection, initial text size, and weight. The component supports chaining additional formatting methods, such as setting the text size (e.g., Tiny, Small, Medium, etc.) and text weight (e.g., SemiBold).
Below is a basic example:
API reference
public class TextBlock : ComponentBase<TextBlock, HTMLElement>, ITextFormating, IHasBackgroundColor, IHasForegroundColor, ICanWrap, IRoundedStyleA text block component.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<TextBlock, HTMLElement> → TextBlock
- Implements
- ITextFormating, IHasBackgroundColor, IHasForegroundColor, ICanWrap, IRoundedStyle
Constructors
| Name | Description |
|---|---|
| TextBlock | Initializes a new instance of the TextBlock class. |
| Overload | |
|---|---|
| TextBlock(string, bool, bool, TextSize, TextWeight, string) | Initializes a new instance of the TextBlock class. |
| TextBlock(string) | Initializes a new instance of the TextBlock class. |
TextBlock(string, bool, bool, TextSize, TextWeight, string)
public TextBlock(string text = string.Empty, bool treatAsHTML = false, bool selectable = false, TextSize textSize = TextSize.Small, TextWeight textWeight = TextWeight.Regular, string afterText = null)Initializes a new instance of the TextBlock class.
Parameters
- text string
- The text.
- treatAsHTML bool
- Whether to treat the text as HTML.
- selectable bool
- Whether the text is selectable.
- textSize TextSize
- The text size.
- textWeight TextWeight
- The text weight.
- afterText string
- Optional text to append.
Properties
| Name | Description |
|---|---|
| Background | Gets or sets the background color. |
| Foreground | Gets or sets the foreground color. |
| IsEnabled | Gets or sets whether the component is enabled. |
| IsSelectable | Gets or sets whether the text is selectable. |
| Text | Gets or sets the text. |
| HTML | Gets or sets the HTML content. |
| Title | Gets or sets the title. |
| Size | Gets or sets the text size. |
| Weight | Gets or sets the text weight. |
| TextAlign | Gets or sets the text alignment. |
| IsPrimary | Gets or sets whether the text is primary color. |
| IsSecondary | Gets or sets whether the text is secondary color. |
| IsSuccess | Gets or sets whether the text is success color. |
| IsDanger | Gets or sets whether the text is danger color. |
| IsInvalid | Gets or sets whether the text is invalid color. |
| IsRequired | Gets or sets whether the text block represents a required field. |
| CanWrap | Gets or sets whether the text can wrap. |
| EnableEllipsis | Gets or sets whether to enable ellipsis for overflowing text. |
| EnableBreakSpaces | Gets or sets whether to enable break-spaces. |
| Cursor | Gets or sets the cursor. |
public string Background { get ; set ; }Gets or sets the background color.
public string Foreground { get ; set ; }Gets or sets the foreground color.
public bool IsEnabled { get ; set ; }Gets or sets whether the component is enabled.
public bool IsSelectable { get ; set ; }Gets or sets whether the text is selectable.
public TextAlign TextAlign { get ; set ; }Gets or sets the text alignment.
public bool IsPrimary { get ; set ; }Gets or sets whether the text is primary color.
public bool IsSecondary { get ; set ; }Gets or sets whether the text is secondary color.
public bool IsSuccess { get ; set ; }Gets or sets whether the text is success color.
public bool IsDanger { get ; set ; }Gets or sets whether the text is danger color.
public bool IsInvalid { get ; set ; }Gets or sets whether the text is invalid color.
public virtual bool IsRequired { get ; set ; }Gets or sets whether the text block represents a required field.
public bool EnableEllipsis { get ; set ; }Gets or sets whether to enable ellipsis for overflowing text.
public bool EnableBreakSpaces { get ; set ; }Gets or sets whether to enable break-spaces.
Methods
| Name | Description |
|---|---|
| Render | Renders the component. |
Samples
Basic Text Display
This sample demonstrates how to create a simple text block with default styling.
Advanced Text Formatting
In this example, the TextBlock is customized with advanced styling options such as a larger text size, semi-bold weight, non-wrapping text, and a tooltip.