全景+列表框,wp7,文本被截断并且滚动不起作用

发布于 2024-11-26 11:52:16 字数 1583 浏览 5 评论 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; }
}

我的 xaml 绑定到 List如下。

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

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

知道我做错了什么吗?

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2024-12-03 11:52:16

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

上述内容将解决您眼前的问题,但您还应该解决设计决策,以在全景图中包含大量文本。
全景图并不旨在显示大量文本。将全景图想象成杂志封面。您不会在封面上包含文章。您可以添加标题或图像来吸引观众/用户在杂志中阅读更多内容。这里应该应用同样的原则。让全景图上的内容(标题/标题或等效图像)将用户带到可以阅读完整内容的另一个页面。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文