locked
Horizontal/Vertical Stretch Not Working

    Question

  • Hello,

    I am having textblock inside a button, And I want to fit the textbox to the size of button, tried Horizontal and Vertical stretch but its not working. Only want to stretch control not content.

     <Button Height="200" Width="500">
                <TextBlock HorizontalAlignment="Stretch"  TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Stretch"/>
    </Button>

    Thanks in advance.

    Friday, March 28, 2014 11:00 AM

Answers

  • Thanks for the Reply,

    I also found another solution for that. How can I make textblock content to center of button without disturbing its height and width?

     <Button Height="200" Width="500" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
        <TextBlock   Text="TextBlock"/>
     </Button>


    Friday, March 28, 2014 1:31 PM

All replies

  • Hi,
    You can achieve it like that

     <Button Name="SubmitButton" Height="200" Width="500" Margin="293,142,0,426">
    
                <TextBlock Height="{Binding ElementName=SubmitButton, Path=ActualHeight}" 
                           Width="{Binding ElementName=SubmitButton, Path=ActualWidth}"
                           Text="TextBlock"  />
                
            </Button>

    No other textbox property will help you.

    Regards,


    Ibraheem Osama Mohamed | My Blog | @IbraheemOM | My Website

    (If my reply answers your question, please propose it as an answer)

    Friday, March 28, 2014 12:25 PM
  • Thanks for the Reply,

    I also found another solution for that. How can I make textblock content to center of button without disturbing its height and width?

     <Button Height="200" Width="500" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
        <TextBlock   Text="TextBlock"/>
     </Button>


    Friday, March 28, 2014 1:31 PM
  • Thanks for sharing :) 

    Ibraheem Osama Mohamed | My Blog | @IbraheemOM | My Website

    (If my reply answers your question, please propose it as an answer)

    Friday, March 28, 2014 6:43 PM
  • Hello,

    By default textblock content is at top left, how can I put the content in the center of a button without disturbing original height and width of the textblock.

    Thanks in advance.

    Monday, March 31, 2014 5:20 AM
  • Hi,

    Set The TextBlock VerticalAlignment and TextAlignment to Center. Some codes below you can refer to:

    <Button Height="200" Width="500" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
                <TextBlock   Text="TextBlock" VerticalAlignment="Center" TextAlignment="Center"/>
            </Button>
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, April 04, 2014 8:05 AM
  • Hi Anne,

    Thanks for the reply, I tried your code it makes content to the center but it also changes the width and height of the textblock. I want the width and height of textblock same as the button width and height and want textblock content to the center of button.


    • Edited by zee_patel Friday, April 04, 2014 8:23 AM
    Friday, April 04, 2014 8:22 AM