0

I have a TextBlock which I want to be as big as possible without being multiple lines. I need to check to see if it flows onto the next line so that I can reduce the size of the text. I cannot set the max lines to 1, because then it will just cut off my text. How Can i see if there are multiple lines being used in my TextBlock?

One way I was thinking of, but could not figure out, is something like:

if(TextBlock.Text.Width > TextBlock.Width)

or

if(TextBlock.Height > TextBlock.Text.Height)

But those don't seem doable from what I have seen.

Evorlor
  • 7,263
  • 17
  • 70
  • 141
  • 1
    Reducing the font size might give a bad user experience.. consider using scroll bars.. – bit Jul 25 '14 at 04:02

1 Answers1

1

I agree with the comment by bit, but if you wish to do this, you can use a ViewBox control and place the TextBlock inside of it.

<Viewbox>
    <TextBlock Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut l"/>
</Viewbox>
Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
  • This is EXACTLY what I have been searching for!! If I add the Stretch="Uniform" property to the XAML, do you know what that does? It appears to do nothing, which leads me to believe it is the default? – Evorlor Jul 26 '14 at 00:34
  • 1
    A Viewbox will take up all the space it is given :) – Shawn Kendrot Jul 26 '14 at 03:14