Scrolling Through a ListView Programmatically with ScrollIntoView()
Programmatically scrolling to a particular item in a ListView has become absurdly easy in WPF. However, it seems that this is not a well-known feature. I've had a number of people ask me about how to do this and if you google on "wpf ScrollIntoView" you will find almost nothing. All you need to do is get a reference to the item you are trying to scroll to and call the ScrollIntoView method, like so:
C#:
-
Object myItem = myList.Items[20];
-
myList.ScrollIntoView(myItem);
Easy, eh? To demonstrate the functionality, I've included this cheezy XBAP example...
March 16th, 2007 at 3:29 pm
what about an listview with ScrollViewer.CanContentScroll=”True”, because i need to scroll item by item, and i delete the last idem until i have an empty list. my problem is that the vertical scrollbar doesn’t dissapier althou the list is empty…..
mylist.ScrollIntoView(mylist.Items[0] dosn;t work
any ideas?
May 13th, 2008 at 11:10 am
Thnks
Very good example