RichTextBuilder Class
Builds a RichText, one span after the other.
public sealed class RichTextBuilderRemarks
A builder is not thread-safe. It can be reused after RichTextBuilder.Build, and emptied with RichTextBuilder.Clear.
Constructors
| Name | Description |
|---|---|
| RichTextBuilder() |
RichTextBuilder()
RichTextBuilder.cspublic RichTextBuilder()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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.csAdds a text with a style.
public RichTextBuilder Append(string text, TextStyle style)AppendPlaceholder(double, double, double, TextStyle)
RichTextBuilder.csAdds 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
widthdouble- The width of the placeholder, in pixels: zero or positive, up to 65536.
heightdouble- The height of the placeholder, in pixels: zero or positive, up to 65536.
baselinedouble- The distance from the top of the placeholder down to the baseline of its line, in pixels:
heightto stand on the baseline. Its magnitude must not exceed 65536. styleTextStyle- The style of the placeholder: the one of the text around it, as a rule.
Returns
RichTextBuilder This builder.
Exceptions
ArgumentNullExceptionstyleisnull.ArgumentOutOfRangeExceptionwidthorheightis not between 0 and 65536, orbaselineis 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.
Build()
RichTextBuilder.csClear()
RichTextBuilder.csRemoves every span.
public void Clear()