views:

1845

answers:

1

How can I programmatically force a silverlight list box to scroll to the bottom so that the last item added is always visible.

I've tried simply selecting the item. It ends up as selected but still not visible unless you manually scroll to it.

+8  A: 

Use the ListBox's ScrollIntoView method passing in the last item. You may need to call UpdateLayout immediately before it for it to work.

Bill Reiss
This is exactly the answer I was looking for except... I can't get it to work. It seems like this should work... If lst.Items.Count > 0 Then lst.SelectedIndex = lst.Items.Count - 1 lst.ScrollIntoView(lst.SelectedItem) lst.UpdateLayout() ElseThe last item is selected but not in view.
Call UpdateLayout BEFORE ScrollIntoView, hopefully that will work for you.
Bill Reiss
That did the trick. Works exactly as I wanted now. Thank you.