This is a migrated thread and some comments may be shown as answers.

Item realization issues with ScrollToHorizontalOffset (virtualization)

3 Answers 116 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajen
Top achievements
Rank 1
Rajen asked on 20 Oct 2013, 09:47 PM
Hi,

I'm using the RadDataBoundListBox control to display a large number of images (binding to IEnumerable<byte[]> and using a Converter to display the actual images). Everything seems to be working properly, but I have a requirement to manually scroll through the list using pixel offsets.

I can get the list to scroll with the following code:

private ScrollViewer _listBoxScrollViewer;
_listBoxScrollViewer = listBox.ChildrenOfType<ScrollViewer>().FirstOrDefault();
_listBoxScrollViewer.ScrollToHorizontalOffset(_listBoxScrollViewer.HorizontalOffset + 512);

The problem occurs after scrolling a few times to the right where the items haven't realized yet (due to the virtualization). The problem is that calling ScrollToHorizontalOffset does not actually trigger the realization of the items, so the list becomes blank after scrolling using this method. The only way to trigger the items to realize is to manually touch the RadDataBoundListBox control, which pretty much defeats the purpose.

Is there any way to trigger the item realization when manually scrolling a RadDataBoundListBox with ScrollToHorizontalOffset?

3 Answers, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 21 Oct 2013, 02:44 PM
Hello Rajen,

Thanks for writing.

RadDataBoundListBox implements a custom UI virtualization mechanism that uses the change of visual states of the ScrollViewer (scrolling -> not-scrolling -> scrolling) to trigger the UI virtualization logic. When you directly set the scrolloffset of the ScrollViewer component the UI virtualization mechanism is bypassed and therefore you get the undesired behavior you observe.

While in some cases explicitly setting a scroll offset might work as expected, in other cases this might not yield the expected result. Imagine that you set a big enough scroll offset that makes all realized items be recycled and disappear: what would be the data index to start realizing from based on the scroll offset provided that items may have different sizes? We may use some predictions but ultimately the behavior will not be deterministic.

Otherwise you can trigger the virtualization logic by calling the BalanceVisualSpace method which is defined by the base RadVirtualizingDataControl class and is internal. You should use reflection to do that.

I hope this helps.

Regards,
Deyan
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Rajen
Top achievements
Rank 1
answered on 21 Oct 2013, 09:29 PM

Hi Deyan,

Thanks for the elaboration, your suggestion to manually call the BalanceVisualSpace method worked! For future reference, here's how to call it:

private MethodInfo _balanceVisualSpaceMethod;
_balanceVisualSpaceMethod = listBox.GetType().GetMethod("BalanceVisualSpace", BindingFlags.NonPublic | BindingFlags.Instance);
_balanceVisualSpaceMethod.Invoke(listBox, null);

0
Alex
Top achievements
Rank 1
answered on 07 Feb 2014, 05:57 AM
Thank you for all your posts and advices.
I decided not to use reflection, but still call BalanceVisualSpace.
After 5 minutes in JustDecompile, I ended with following code:

01.//I checked exact value of RealizedItemsBufferScale on exact page and it's 2 by default in my case
02.var currentBufferScale = telerikListBox.RealizedItemsBufferScale;
03.if (currentBufferScale >  2.0000002)
04.{
05.    currentBufferScale -= 0.0000001;
06.}
07.else
08.{
09.    currentBufferScale += 0.0000001;
10.}
11.telerikListBox.RealizedItemsBufferScale = currentBufferScale;

Telerik Team, please make method BalanceVisualSpace public in upcoming release.
Thank you.



Tags
DataBoundListBox
Asked by
Rajen
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Rajen
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Share this question
or