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

How to keep viewport items when changing VirtualizationStrategyDefinition

4 Answers 66 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.
Lion Pham
Top achievements
Rank 1
Lion Pham asked on 10 Aug 2014, 07:27 PM
Hello,

I have the following scenario:

I have a DataBoundListBox which has 10 items. The current viewport item is 5 and the DataBoundListBox has Horizontal-orientation StackVirtualizationStrategyDefinition as the value of VirtualizationStrategyDefinition property.
Now, I change orientation of the StackVirtualizationStrategyDefinition to Vertical. The problem is the viewport item is changed to 1 instead of 5.

How can I keep viewport items when changing VirtualizationStrategyDefinition of DataBoundListBox?

My solution for this scenario is:
Assume that I have a button is used to change orientation value of the StackVirtualizationStrategyDefinition. After clicking this button, I will do the following works:
- Firstly, I will change orientation value of the StackVirtualizationStrategyDefinition, in this case I will change the orientation value from Horizontal to Vertical
- Secondly, delay the current thread for 500ms by using await Task.Delay(TimeSpan.FromMilliseconds(500));
- And lastly, use te BringIntoView method to bring the viewport item (5) into view.

The reason why I use Task.Delay is because BringIntoView method was not working correctly without it. I think the reason of this problem is when I change orientation value of the StackVirtualizationStrategyDefinition, DataBoundListBox needs time to load items to view with new orientation. The BringIntoView method is called too soon before items are loaded will not work as expected.

I think these is a better solution for my problem. Looking forward to your help.

Best

4 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 13 Aug 2014, 11:20 AM
Hello,

Thank you for the question.

Instead of using Task.Delay(...), you can call the BringIntoView method in a Dispatcher.BeginInvoke(...) call whenever you change the orientation. I have attached a sample project for demonstration.

I hope this helps. Please, let us know if you have further questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lion Pham
Top achievements
Rank 1
answered on 14 Aug 2014, 08:06 PM
Hello,

Thank you for replying my question.

Good news! Your solution worked :). However, Could you explain why I should wrap the BringIntoView() call to the Application.Current.RootVisual.Dispatcher() in this case?

Best,
0
Lion Pham
Top achievements
Rank 1
answered on 15 Aug 2014, 04:33 AM
Hello,

It seems that your solution actually didn't work properly. Please reproduce the following:
- Create a RadDataBoundLitsBox with ItemsSource is a list of 20+ different image
- Scroll to any image (10th image for example)
- Change Orientation of VirtualizationStrategyDefinition from Horizontal to Vertical and vice versa 4+ times

At my end, in the first time I change Orientation of VirtualizationStrategyDefinition, it worked correctly, the viewport item (10th image) is scrolled properly. However, after that, it did not work, the RadDataBoundLitsBox scrolled to 19th image.

Please check it.

Thank you



0
Accepted
Rosy Topchiyska
Telerik team
answered on 19 Aug 2014, 02:30 PM
Hello,

Thank you for the information.

When the BringIntoView() method is called, the position of the item is not calculated correctly if the items do not have fixed Width/Height. This happens because RadDataoundListBox uses UI virtualization and it calculates average height/width of the realized items. Could you please make sure that this condition is satisfied in your scenario. If this does not solve the problem, could you send us a sample project that reproduces it.

I hope this help. Please, let us know if you have further questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataBoundListBox
Asked by
Lion Pham
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Lion Pham
Top achievements
Rank 1
Share this question
or