#339 – Wrapping a Button’s Text Content to Multiple Lines
July 11, 2011 1 Comment
When a Button control automatically sizes to fit its content, it will grow to fit the text in the Content property. However, the text will always remain on a single line.
<Button Content="Click me if you want to see something cool. In fact, click as many times as you like." HorizontalAlignment="Center" VerticalAlignment="Center"
If you constrain the button’s Width, however, the text will be clipped.
To get the text on a face of a Button to wrap, you can use a TextBlock as the button’s Content, rather than a simple text string. You also set the TextWrapping property on the TextBlock.
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" Width="120"> <TextBlock Text="Click me if you want to see something cool. In fact, click as many times as you like." TextWrapping="Wrap"/> </Button>