0

this are many similar questions asked to this but no good answer? i use context drawing to draw input text on a certain rect size "720,576", now i need to fit the whole text in that to the maximum font size, while maintaining the rows count?

i tried to create an equation to calculate that but no use. i even tried to loop size till text is clipped but i couldn't test that condition, and i searched for a week to see something similar but no avail!

lastly i tried to use a view box which is near what i want but it wont let the textblock inside to multiline as it always re-size the width contain all text in one line.

here is what i got:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="720" Width="576">
<Viewbox >
    <TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center Text="how are you doining how are you doining how are you doining how are you doining how are you doining how are you doining how are you doining how are you doining how are you doining" " />
</Viewbox>

any help would be appreciated, thanks.

bat3a
  • 31
  • 4

2 Answers2

0

i cannot reproduce the behaviour you describe with just you example copy/pasted into a new project. It does write the text on several lines; Maybe you have a default setter on one object, maybe textbox...

OK very easy : set the width on your TextBox, so your TextBox will wrap. Maybe you wanna have as width the width of the ViewBox (ancestor binding).

GameAlchemist
  • 18,995
  • 7
  • 36
  • 59
0

I've had the same issue. Here is a fix:

<Viewbox StretchDirection="DownOnly">
    <Grid MaxWidth="1000" MaxHeight="100">
         <TextBlock TextWrapping="Wrap" FontSize="42" VerticalAlignment="Center" Text="very very very very very very very very very very very very very very very very long line"/>
    </Grid>
</Viewbox>

So with extending the text line it will be resized till it is not so small, then it will be wrapped to next line

giacoder
  • 980
  • 8
  • 21