Tuesday, September 9, 2008

Silverlight Tip 3#: ScrollIntoView

When you programmatically set selected item in a ListBox control and the item is unvisible, the Listbox doesn't automatically scroll to make it visible. But you can use ScrollIntoView method.


this.DropDownListBox.SelectedIndex = index;
this.DropDownListBox.UpdateLayout();
this.DropDownListBox.ScrollIntoView(this.DropDownListBox.SelectedItem);

4 comments:

Tanmoy Rajguru (Code name MRGNI) said...

Thanks. I was stucked in this issue :)

Aviw said...

ScrollIntoView doesn't work for me...

Andrzej said...

I had a problem with ScrollIntoView not working properly in scrollbar-less ListBox, turns out I had ScrollViewer.VerticalScrollBarVisibility set to "Disabled".

After switching to "Hidden", it worked.

Samuel Mandell said...

Adding a call to UpdateLayout on the list is what fixed it for me. Thanks!