How to keep viewport items when changing VirtualizationStrategyDefinition

5 posts, 1 answers
  1. Lion Pham
    Lion Pham avatar
    13 posts
    Member since:
    May 2013

    Posted 10 Aug 2014 Link to this post

    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

  2. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 13 Aug 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Lion Pham
    Lion Pham avatar
    13 posts
    Member since:
    May 2013

    Posted 14 Aug 2014 in reply to Rosy Topchiyska Link to this post

    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,
  5. Lion Pham
    Lion Pham avatar
    13 posts
    Member since:
    May 2013

    Posted 14 Aug 2014 in reply to Lion Pham Link to this post

    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



  6. Answer
    Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    551 posts

    Posted 19 Aug 2014 Link to this post

    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.

     
Back to Top
DevCraft banner