当列表内有列表时,可滚动高度发生变化时,VerticalOffset的变化方式 [英] How VerticalOffset changes when Scrollable height changes while having list inside a list

查看:139
本文介绍了当列表内有列表时,可滚动高度发生变化时,VerticalOffset的变化方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个具有UserControls列表框的WP7应用程序。每个UserControl都有一个ItemsControl和Button(用于获得更多结果)。单击按钮后,ItemsControl项将增加5或10。

I am making a WP7 app which has a Listbox of UserControls. Each UserControl has an ItemsControl and Button(for getting more results). On click of the button the ItemsControl items will be increased by 5 or 10.

现在,单击除第一个或最后一个以外的任何用户控件的GetMore按钮,将增加ListBox的可滚动高度(Listbox的总高度),但ListBox的VerticalOffset(滚动条从顶部开始的位置)保持不变。现在我面临的问题是垂直偏移不是绝对的,而是相对于可滚动高度的。因此,在此之前被查看的内容将基于ScollableHeight的新值进行更改。

Now on clicking on the GetMore button of any of the usercontrols except the first or last, there will be an increase in Scrollable height(Total height of the listbox) of the ListBox but the VerticalOffset(position of scrollbar from top) of the ListBox remains same. Now the problem I am facing is that the Vertical Offset is not absolute but relative to Scrollable Height. So the content being viewed till then will be changed basing on the new value of ScollableHeight.

我想知道它们之间的关系,以便我可以做一些数学运算和设置VerticalOffset值。

I want to know the relation between them, so that I can do some math and set the VerticalOffset value.

我在VerticalOffset和ScrollableHeight中添加了一些依赖项属性,通过它们可以在更改任何事件时获取事件。尝试使用ScrollIntoView重新调整垂直偏移量

I have added some dependency properties on VerticalOffset and ScrollableHeight through which I can get the events when any of them is changed. Trying to use ScrollIntoView for readjusting the Vertical Offset

任何建议或更正均受到高度赞赏。

Any suggestions or corrections are highly appreciated.

推荐答案

我找不到计算。但是可以做的是,将列表框替换为内部具有itemsControl的scrollviewer。但是,这样做的缺点是虚拟化被禁用,因此需要对此进行检查。

I am not able to find the calculation. But what can be done is listbox can be replaced by a scrollviewer which has itemsControl inside it. But the disadvantage of this is virtualisation is disabled, so will need to check on this.

但是,总的来说,这将给用户在使用此类UserControl时带来不好的体验。列表框。因此,使用WP7工具包中提供的模板化列表框是一种选择,但是由于ListBox并未针对多模板化虚拟化进行优化,因此它会挂掉一点。因此,我开始显示编写列表框项目模板的方式,其中包含从条件中启用的所有可能的布局。

But, overall this is going to give a bad experience on using such a UserControl in Listbox. So using templated list box given in WP7 toolkit is an option but it is gonna hang a bit since ListBox is not optimized for multi templated virtualization. So I started showing writing listbox item template in such a way it contains all the possible layouts which will enabled from a condition.

这篇关于当列表内有列表时,可滚动高度发生变化时,VerticalOffset的变化方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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