This question is locked. New answers and comments are not allowed.
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
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