0

我正在使用全景控件。在每个 PanoramaItem 内,我都有一个 ListBox。ListBox 包含一堆 TextBlock;原因是因为我正在显示很长的文本,并且从另一篇文章中,我发现 wp7 在显示长文本时有限制。

例如,我有两个对象定义如下。

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; }
}

我要绑定到 List<DisplayItem> 的 xaml 如下。

<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>

所有数据都正确绑定,但是,当我尝试滚动 ListBox 时,它会停止而不会一直到底部。对我来说效果是“滚动不起作用”和“文本被截断”。

关于我做错了什么的任何想法?

作为旁注,我还发布了一个关于显示超长文本的问题(即最终用户许可协议 EULA)。一位用户通过给我一个指向他制作的控件的链接来响应,以显示很长的文本。帖子是Silverlight TextBlock 可以容纳多少个字符?. 当我使用该控件和/或方法来存储我的长文本时,我得到了相同的效果。

4

1 回答 1

4

如果您在 StackPanel 中有一个 ListBox,则框架无法确定控件的高度以及是否应启用滚动。

在 DataTemplate 中使用 Grid 而不是 StackPanel。

<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>

以上将解决您的直接问题,但您还应该解决在全景图上包含大量文本的设计决策。
全景图并非旨在显示大量文本。将全景图想象成杂志封面。你不会在封面上写一篇文章。您将包含标题或图片以吸引观众/用户在杂志中阅读更多内容。在这里应该应用相同的原则。在全景图上有内容(标题/标题或等效图像)将用户带到另一个页面,在那里他们可以阅读完整内容。

于 2011-07-25T16:02:21.303 回答