4
votes

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

3
Can't you just store the scroll-position and set the scroll-position back manually after the refresh?Kolky
if for example the user is at the top of the list, the offset will be 0. When new items are added the offset will still be 0.Ade A

3 Answers

1
votes

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.

[1] http://tombstonehelper.codeplex.com/SourceControl/changeset/view/e737b2a34421#TombstoneHelper%2fListBoxTombstoner.cs

0
votes

Try to set IsSynchronizedWithCurrentItem="True" on the ListBox

0
votes

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.