Sky Kim
Sky Kim

Reputation: 179

UWP Win2D draw text with specified width? Is it possible?

I like to draw text "Hello Test Text" with specific 'Width' of the string bound in UWP app with Win2D.

Here is why I need:

<Viewbox Stretch="Uniform" Width="auto" Height="auto">
                    <TextBlock x:Name="txtSignaturePreview" Text="Sample Text" Foreground="White" />
                </Viewbox>

With this code, I can resize the text by changing Viewbox's width. Font size of "Sample Text" changes to fit into the width.

I like to do the same thing with Win2D DrawText.

CanvasDrawingSession.DrawText Method (String, Rect, Color, CanvasTextFormat)

DrawText's rectangle is just limit and force the text wrap. Only solution I found to achieve the goal is changing font size and pass it via CanvasTextFormat. But, the issue is I cannot find a solution to figure it out the desirable font size with give string Width to fit in.

Any help?

Upvotes: 2

Views: 646

Answers (1)

Sky Kim
Sky Kim

Reputation: 179

Here is the updated answer with own research.

I confirmed that this is not possible in easy way with the current available methods after msdn forum discussion with MSFT guy. Win2D does not support.

Rather I did work around; I calculate the font size based on the width ratio. Font Size is double and it is pretty accurate and works well so far.

Upvotes: 2

Related Questions