Reputation: 146
My problem is that I have a databinded ItemsControl with some data presented in a list and user can scroll up and down.
When adding new items to the list (i.e. user refreshes the list), the scroll position moves according to however many new items there are. Is there a way to keep the scroll position upon adding new items?
Thanks
Upvotes: 4
Views: 1135
Reputation: 56853
If you have a look at the TombStone Helper project on Codeplex in the ListBoxTombstoner.cs class [1] you will find code which allows you to get at the underlying ScrollViewer for the listbox and get its VerticalOffset property.
You will then be able to manipulate this property however you want - either adding to it if you want the scroll position to move as you add items, or keep it the same.
Upvotes: 1
Reputation: 65556
Assuming that all items are of a fixed height you should be able to adjust the the ScrollOffset after the addition-being sure to take the number of added items into consideration.
Upvotes: 0