locked
Stretching the Text in a TextBlock RRS feed

  • Question

  •  

    Hello everyone!

     

    I have TextBlock which looks like this:

     

    Code Snippet

     

    <TextBlock Name="tbText" Text="1 2345 6789" Width="200"

    HorizontalAlignment="Stretch" VerticalAlignment="Top" Background="Green"/>

     

     

    How is it possible to stretch my Text in the TextBlock to the size of the TextBlock? I have tried it with the Property HorizontalAlignment, but nothing happens.

     

    Could anyone help me?

    Wednesday, February 20, 2008 9:06 AM

Answers

  • When you set TextBlock.HorizontalAlignment to Stretch (which is the default value) you're stretching the TextBlock, not its content.

     

    To achieve the behavior you're looking for, you'll have to code a Control of your own. If I have time for it, I'll post a sample.

    Wednesday, February 20, 2008 11:39 AM

All replies

  • When you set TextBlock.HorizontalAlignment to Stretch (which is the default value) you're stretching the TextBlock, not its content.

     

    To achieve the behavior you're looking for, you'll have to code a Control of your own. If I have time for it, I'll post a sample.

    Wednesday, February 20, 2008 11:39 AM
  • Oh, thanks a lot for your answer!

     

    Yeah, a sample would be nice.

     

    Wednesday, February 20, 2008 11:47 AM