Silverlight textblock in the list does not wrap

I have a list of data with a binding as shown below. I want a text block that contains data to be wrapped. And I couldn’t.

What is the problem here?

Here is my code:

<DataTemplate x:Key="policyLbTemplate"> <StackPanel> <TextBlock Text="{Binding name}" FontWeight="Bold"/> <TextBlock Text="{Binding description}" TextWrapping="Wrap" /> </StackPanel> </DataTemplate> <ListBox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding Policies}" ItemTemplate="{StaticResource policyLbTemplate}" HorizontalContentAlignment="Stretch" /> 
+4
source share
2 answers

This is most likely because there is nothing to limit the width of the TextBlock so that it grows overs. Do horizontal scrollbars appear?

See the following related questions and try the solutions described:

WP7 TextBlock inside ListBox, no wrapping text

Force TextBlock to Migrate to ListBox WPF

windows phone 7 TextBlock TextWrapping not listed

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/37236ac6-05c3-4acc-baca-abc871ba64e0

+2
source

You need to add one property to the list: ScrollViewer.HorizontalScrollBarVisibility="Disabled" , then the text will be wrapped (otherwise it will grow overs). I did this in the following code and it works great for me.

 <ListBox Name="lstbIcons" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding UserActionName}" FontWeight="Bold"/> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 
+5
source

All Articles