Sonntag, 16. Oktober 2011

Windows Phone 7: Issue with Textblock and Textbox rendering

There is an issue with Silverlight for Windows Phone if you try to show a Textblock or Textbox with a lot of text. In my current Windows Phone 7 project with have a listbox with comments and with large text sizes (above 3300 in our test cases) we have the effect that the space for the text is rendered but not all characters.

The result looks like this:

 image

This happens if the surrounding container object (for example Grid or Stackpanel) has a defined width and the Textbox or Textblock has the VerticalAlignment set to “Stretch”.

The XAML definition looks like this:

   1:  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
   2:              <ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged">
   3:                  <ListBox.ItemTemplate>
   4:                      <DataTemplate>
   5:                        <StackPanel Margin="0,0,0,17" Width="432" >
   6:                            <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
   7:                            <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" 
   8:                                       VerticalAlignment="Stretch"
   9:                                       Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
  10:                        </StackPanel>
  11:                      </DataTemplate>
  12:                  </ListBox.ItemTemplate>
  13:              </ListBox>
  14:   </Grid>

The workaround for this problem is to truncate the text after 3300 characters or don’t use a fix width for the container of the Textbox or Textblock element.

The behaviour is the same in Windows Phone 7.0 and Windows Phone 7.1 projects.

Keine Kommentare:

Kommentar veröffentlichen