Search code examples
wpfxamlwindows-phone-8

Textblock apply linebreak for each item in listbox item template


I have the following xaml code for a list box. Thing is I want to apply a line break at the end of each textblock after it is rendered. Currently I am only getting a linebreak at the end of first item. But I dont get the line break for the remaining items. Please help. Dont worry about the Itemsource for the list box its being bound from the cs.

 <ListBox Name="lstreviews" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="470">
       <ListBox.ItemTemplate>
           <DataTemplate>
               <Grid>
                   <Grid.RowDefinitions>
                       <RowDefinition Height="Auto"></RowDefinition>
                       <RowDefinition Height="Auto"></RowDefinition>
                       <RowDefinition Height="Auto"></RowDefinition>
                   </Grid.RowDefinitions>
                   <Grid.ColumnDefinitions>
                       <ColumnDefinition Width="Auto"></ColumnDefinition>
                       <ColumnDefinition Width="Auto"></ColumnDefinition>
                   </Grid.ColumnDefinitions>
                   <TextBlock Grid.Row="0" Grid.Column="0" Text="Name:"></TextBlock>
                   <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding author_name}"></TextBlock>
                   <TextBlock Grid.Row="1" Grid.Column="0" Text="Rating:"></TextBlock>
                   <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding rating}"></TextBlock>
                   <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" TextWrapping="Wrap" Width="360" Text="{Binding text}">
                       <LineBreak></LineBreak>
                   </TextBlock>
               </Grid>
           </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox>

Solution

  • A line break is just empty space. Just add a bottom margin to your Grid. You are making it too complicated with the line break :).