- SenlyCamile
- Posts: 20
- Joined:
Is there any demo about how to use the class FormattedText?
I wanna to use DrawingContext to drawtext. I tried to get formattedtext from a textblock.But it did not work.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Is there any demo about how to use the class FormattedText?
Hi, to draw a text using a FormattedText first provide the text or inlines that will generate the text runs, and then call the layout method to place the text according to the provided bounds and font properties.
Code: Select all
void OnRender(DrawingContext* context)
{
mFormattedText->BuildTextRuns(mText.Str(), nullptr, mFont, FontWeight_Normal, FontStretch_Normal, FontStyle_Normal,
12.0f, 0.0f, nullptr, mForegroundBrush, nullptr, TextDecorations_None, 1);
mFormattedText->Layout(TextAlignment_Left, TextWrapping_Wrap, TextTrimming_None, mRenderSize.width, mRenderSize.height,
0.0f, LineStackingStrategy_MaxHeight);
context->DrawText(mFormattedText, Rect(mRenderSize));
}
- SenlyCamile
- Posts: 20
- Joined:
Re: Is there any demo about how to use the class FormattedText?
Thanks!Hi, to draw a text using a FormattedText first provide the text or inlines that will generate the text runs, and then call the layout method to place the text according to the provided bounds and font properties.Code: Select allvoid OnRender(DrawingContext* context) { mFormattedText->BuildTextRuns(mText.Str(), nullptr, mFont, FontWeight_Normal, FontStretch_Normal, FontStyle_Normal, 12.0f, 0.0f, nullptr, mForegroundBrush, nullptr, TextDecorations_None, 1); mFormattedText->Layout(TextAlignment_Left, TextWrapping_Wrap, TextTrimming_None, mRenderSize.width, mRenderSize.height, 0.0f, LineStackingStrategy_MaxHeight); context->DrawText(mFormattedText, Rect(mRenderSize)); }
Who is online
Users browsing this forum: Bing [Bot] and 94 guests