Ade A
Ade A

Reputation: 146

Keep position in scrollviewer

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

Answers (3)

samjudson
samjudson

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.

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

Upvotes: 1

Matt Lacey
Matt Lacey

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

Stecya
Stecya

Reputation: 23266

Try to set IsSynchronizedWithCurrentItem="True" on the ListBox

Upvotes: 0

Related Questions