Scroll to item in listview in Silverlight 3.
Posted
by the empirical programmer
on Stack Overflow
See other posts from Stack Overflow
or by the empirical programmer
Published on 2010-04-16T22:41:12Z
Indexed on
2010/04/16
22:43 UTC
Read the original article
Hit count: 162
I have a silverlight 3 app with a textbox on the main window and a childwindow that has a list of all the potential textbox values. When I open that childwindow I want it to scroll to the correct one in the list.
I'm trying to do this with the code below...using the ScrollIntoView. It was not working at all until I add the UpdateLayerout(). However it does not seem to work all the time. At times it scrolls but not all the way to the item, it is a few items higher than it should be. The listbox is in an Accordion and the list items use a ItemTemplate\DataTemplate, not sure if that effects anything but thought I'd mention it.
Any ideas what I'm missing in the code below?
What I would like is to scroll the item to the top of the list ....any ideas how to that?
(Or any other suggestions on how to code this better)
Thanks!
for (int index = 0; index < myList.Items.Count; index++) {
object obj = myList.Items[index];
var listItem= obj as listItemObject;
if (listItemObj != null) {
if (string.Compare(listItemObj.id, _PastedInId, StringComparison.InvariantCultureIgnoreCase) == 0) {
selectThisIndex = index;
scrollToThisItem = obj;
}
}
}
myList.SelectedIndex = selectThisIndex;
if (scrollToThisItem != null){
myList.UpdateLayout();
myList.ScrollIntoView(scrollToThisItem);
}
© Stack Overflow or respective owner