TextBlock renders read-only text with optional wrapping, alignment, and trimming.
new TextBlock("Hello, world!");
TextBlock supports a dynamic text provider via a Func<string>:
var count = new State<int>(0);
new TextBlock(() => $"Count: {count.Value}");
new TextBlock("This is a long line that can wrap.")
.Wrap(true);
new TextBlock("This is a long single line that will be trimmed.")
.Wrap(false)
.Trimming(TextTrimming.EndEllipsis);
TextAlignment controls how the text is aligned inside the available width:
new TextBlock("Centered")
.TextAlignment(TextAlignment.Center)
.HorizontalAlignment(Align.Stretch);
HorizontalAlignment = Align.Start, VerticalAlignment = Align.StartUse TextBlockStyle to override colors and decorations for a subtree (or for a single TextBlock):
new TextBlock("Accent")
.Style(TextBlockStyle.Default with
{
Foreground = Colors.DeepSkyBlue,
TextStyle = TextStyle.Bold,
});
To apply a background only behind the glyphs, set Background:
new TextBlock("Highlighted")
.Style(TextBlockStyle.Default with
{
Background = Colors.Blue,
Foreground = Colors.White,
});
To fill the whole bounds with a background, enable FillBackground:
new TextBlock("Banner")
.HorizontalAlignment(Align.Stretch)
.Style(TextBlockStyle.Default with
{
Background = Colors.Blue,
Foreground = Colors.White,
FillBackground = true,
});