Question

i am using a Panorama control. inside each PanoramaItem, i have a ListBox. the ListBox holds a bunch of TextBlock; the reason is because i am displaying very long text and from another post, i found out that wp7 has limitations when displaying long text.

for example, i have two objects defined as follows.

public class TextItem {
 public string Text { get; set; }
}

public class DisplayItem {
 public string Header { get; set; }
 public string FullHeader { get; set; }
 public List<TextItem> TextItems { get; set; }
}

my xaml to bind to a List<DisplayItem> is as follows.

<controls:Panorama ItemsSource="{Binding}">
 <controls:Panorama.HeaderTemplate>
  <DataTemplate>
   <TextBlock Text="{Binding Header}" TextWrapping="Wrap"/>
  </DataTemplate>
 </controls:Panorama.HeaderTemplate>
 <controls:Panorama.ItemTemplate>
  <DataTemplate>
   <StackPanel Orientation="Vertical">
    <TextBlock Text="{Binding FullHeader}" TextWrapping="Wrap"/>
    <ListBox ItemsSource="{Binding TextItems}">
     <ListBox.ItemTemplate>
      <DataTemplate>
       <TextBlock Text="{Binding Text}"/>
      </DataTemplate>
     </ListBox.ItemTemplate>
   </StackPanel>
  </DataTemplate>
 </controls:Panorama.ItemTemplate>
</controls:Panorama>

all the data bind properly, however, when i attempt to scroll the ListBox, it stops without ever going all the way to the bottom. the effect is to me is that "scrolling isn't working" and "text is truncated."

any idea on what i am doing wrong?

as a side note, i also posted a question on displaying very long text (i.e. an end-user license agreement EULA). a user responded by giving me a link to a control he made to display very long text. the post is at how many characters can a Silverlight TextBlock hold?. when i use that control and/or approach to store my long text, i get the same effect.

Was it helpful?

Solution

If you have a ListBox inside a StackPanel the framework is not able to determine the height of the controls and whether scrolling should be enabled.

Use a Grid instead of a StackPanel inside your DataTemplate.

<DataTemplate>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" /> 
      <RowDefinition Height="auto" />
    </Grid.RowDefinitions>
    <TextBlock Text="{Binding FullHeader}" TextWrapping="Wrap"/>
    <ListBox ItemsSource="{Binding TextItems}" Grid.Row="1">
      <ListBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Text}"/>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
  </Grid>
</DataTemplate>

The above will solve your immediate problem but you should also address the design decision to include a large amount of text on a panorama.
A panorama is not intended to display a large amount of text. Think of a panorama as being like a magazine cover. You wouldn't include an article on the cover. You'd include a headline or image to entice the viewer/user to read more within the magazine. The same principle should be applied here. Have content (a headline/title or equivalent image) on the panorma take the user to another page where they can read the full content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top