如何构建带有重复标题的分页ItemsControl或Panel? [英] How do I build a paged ItemsControl or Panel with a repeating header?

查看:90
本文介绍了如何构建带有重复标题的分页ItemsControl或Panel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个Panel或ItemsControl,以以下形式显示项目:

标题1

  • 子项目1
  • 子项目2
  • 子项目3

标题2

  • 子项目1
  • 子项目2

这很容易,但是这里要注意的是,我需要能够以分页的方式拆分项目.根据控件的高度,不适合的内容将出现在下一页上(依此类推).如果子项目之间发生分裂,我也需要在下一页上重新显示相应的标题.

我在使用MeasureOverride和ArrangeOverride方面取得了一些进展,但是我一直陷入困境.确实令人沮丧,因为这在计算上是微不足道的,但却是在WPF/Silverlight中完成的噩梦.如果您曾经使用过报表包,则此概念非常相似.

我继续回到一个事实,直到将子级添加到控件中之前,我才能确定高度(使用Dispatcher.BeginInvoke).

有人对此有任何建议吗?预先感谢!


修改

[WPF] ObservableCollection和ListBoxItem DataTemplate生成问题

上面的链接与mdm20所建议的非常相似,但是我仍然很困惑.每当我尝试获取ActualHeight时,它都会返回0.此外,除非将调用包装在Dispatcher.BeginInvoke操作中,否则Silverlight 3中的ItemContainerGenerator会为容器返回null.

解决方案

在构造UIElement之前,确实不可能直接测量它,但是您可以通过以下方式构造列表元素:会提前知道他们将占用多少空间.例如,您可以使用Grid布置每个元素,标题的行高度为已知(例如headerHeight),而每个子项的行高度为已知(例如subitemHeight) .然后,您可以通过论坛headerHeight + numSubitems * subitemHeight计算每个元素的高度.另外,如果您知道项目数量会很少,例如少于1000,您可能只想继续创建所有项目,因为那时候性能损失是可以忍受的.

我同意这种事情可能会令人讨厌,但是正是框架的灵活性导致了问题.这个高度计算问题使在ListBox或ListView中平滑滚动但仍虚拟化的项目列表变得如此困难.

I'm trying to build a Panel or ItemsControl that will display items in the form of:

Header 1

  • Sub Item 1
  • Sub item 2
  • Sub Item 3

Header 2

  • Sub Item 1
  • Sub item 2

This is easy enough, but the catch here is that I need to be able to split the items in a Paged fashion. Based on the height of the control, whatever does not fit will be on the next Page (and so on). If a split occurs between subitems, I need to re-display the corresponding header on the next page as well.

I made some progress working with MeasureOverride and ArrangeOverride but I keep running into dead-ends. It's really frustrating because this is something that is computationally trivial but a nightmare to accomplish in WPF/Silverlight. If you have ever worked with reporting packages, the concept is very similar to this.

I keep coming back to the fact that I can't determine the height until after I have added the children to the control (using Dispatcher.BeginInvoke).

Does anyone have any suggestions for accomplishing this? Thanks in advance!


Edit

[WPF] ObservableCollection and ListBoxItem DataTemplate generation problem

This above link is very similar to what mdm20 has suggested, but I am still stuck. Everytime I try to get the ActualHeight, it returns 0. Additionally, the ItemContainerGenerator in Silverlight 3 returns null for the container unless I wrap the call in a Dispatcher.BeginInvoke operation.

解决方案

It is indeed impossible to directly measure a UIElement until you have constructed it, but you might be able to construct the list elements in such a way that you will know in advance how much space they will take up. For example, you could use Grid to lay out each of the elements, with a row of known height (say headerHeight) for the header and rows of known height for each of the sub-items (say subitemHeight). You could then calculate the height of each element by the forumula headerHeight + numSubitems * subitemHeight. Also, if you know that the number of items will be fairly small, say less than 1000, you might just want to go ahead and create them all in advance, since the performance penalty might be tolerable at that point.

I agree that this kind of thing can be annoying, but it's the framework's very flexibility that creates the issue. This height-calculation problem is what makes it so difficult to make a smooth-scrolling--but still virtualized--list of items in a ListBox or ListView.

这篇关于如何构建带有重复标题的分页ItemsControl或Panel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆