Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I wrap text in a TextBlock?

I am new to windows phone7 development and have a little issue.

I have a textblock(Label) in my interface, and in runtime I use that label to display dyanamic data. The problem is when the text is too long(than the width of the screen), it only displays half of the data(Only the content that fits the width). It doesn't matter to go for multiple lines, but I want to display the full content. I tested with Textblock(Label) properties, but didn't find any working.

Can someone please help me. (I am Using visual studio 2010) . Thanks


Following is the XAML

<Grid x:Name="LayoutRoot" Height="98">
    <Ellipse Height="25" HorizontalAlignment="Left" Name="ellipse1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="46" Margin="6,13,0,0" Fill="#FFDB4C4C" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="66,10,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="402" AllowDrop="False" TextWrapping="NoWrap" UseLayoutRounding="True" DataContext="{Binding}" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="66,44,0,0" Name="textBlock2" Text="TextBlock" VerticalAlignment="Top" Width="402" />
</Grid>
like image 582
JibW Avatar asked Dec 12 '22 07:12

JibW


1 Answers

Setting the property TextWrapping = "Wrap" might solve your problem as long as there is enough vertical space.

EDIT

Depending on how you would like the resize behavior this should work:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" MinHeight="40" />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="60" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Ellipse Margin="5" Stroke="Black" StrokeThickness="1" Fill="#FFDB4C4C" />
    <TextBlock HorizontalAlignment="Left" Margin="5" Name="textBlock1"  VerticalAlignment="Top" TextWrapping="Wrap" UseLayoutRounding="True" Grid.Column="1" Text="sdfsdf sdf sdf sdf sd f sdf" />
    <TextBlock  HorizontalAlignment="Left" Margin="5" Name="textBlock2" VerticalAlignment="Top" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Text="sdfsdf sdf sdf sdf sd f sdf" />
</Grid>
like image 94
Emond Avatar answered Dec 20 '22 19:12

Emond