RichTextBuilder Class

Builds a RichText, one span after the other.

public sealed class RichTextBuilder

Remarks

A builder is not thread-safe. It can be reused after RichTextBuilder.Build, and emptied with RichTextBuilder.Clear.

Constructors

NameDescription
RichTextBuilder()

RichTextBuilder()

RichTextBuilder.cs
public RichTextBuilder()

No documentation is available.

Methods

NameDescription
Append(string, TextStyle)Adds a text with a style.
AppendPlaceholder(double, double, double, TextStyle)Adds a placeholder: room in the line for something the text does not draw, such as an icon or a badge, which moves with the text around it when lines are wrapped and aligned.
Build()Creates the text with the spans added so far.
Clear()Removes every span.

Append(string, TextStyle)

RichTextBuilder.cs

Adds a text with a style.

public RichTextBuilder Append(string text, TextStyle style)

Parameters

text string
The text; an empty text adds nothing.
style TextStyle
The style of the text.

Returns

RichTextBuilder This builder.

Exceptions

ArgumentNullException
text or style is null.

AppendPlaceholder(double, double, double, TextStyle)

RichTextBuilder.cs

Adds a placeholder: room in the line for something the text does not draw, such as an icon or a badge, which moves with the text around it when lines are wrapped and aligned.

public RichTextBuilder AppendPlaceholder(double width, double height, double baseline, TextStyle style)

Parameters

width double
The width of the placeholder, in pixels: zero or positive, up to 65536.
height double
The height of the placeholder, in pixels: zero or positive, up to 65536.
baseline double
The distance from the top of the placeholder down to the baseline of its line, in pixels: height to stand on the baseline. Its magnitude must not exceed 65536.
style TextStyle
The style of the placeholder: the one of the text around it, as a rule.

Returns

RichTextBuilder This builder.

Exceptions

ArgumentNullException
style is null.
ArgumentOutOfRangeException
width or height is not between 0 and 65536, or baseline is not between -65536 and 65536.

Remarks

The placeholder is one character of the text (U+FFFC, the object replacement character): it has an index, a caret can be before or after it, and a line can end before or after it. It takes width on its line, and its line is at least as tall as it needs: the placeholder rises baseline above the baseline of the line, and goes height less baseline below it. A placeholder as tall as its baseline stands on the baseline, as a capital letter does.

Nothing is drawn there: TextLayout.Placeholders gives the rectangle of each placeholder of a layout, for the caller to draw in after the text. The style gives the direction and the decorations the placeholder has among its neighbors, and its line the height of its fonts.

In a vertical layout (TextLayoutOptions.WritingMode), the placeholder takes height down its line and is centered on the line, which is at least as wide as width: baseline is not used. With TextOrientation.Sideways, the placeholder is turned with its line as the text is: its rectangle is height wide and width tall.

Creates the text with the spans added so far.

public RichText Build()

Returns

RichText The text; it does not change when the builder does.

Removes every span.

public void Clear()