Recently I have observed that listbox scrollbar has virtualization problem when we re-bind listbox. Let me explain this with an example.
I have added 50 items into listbox control programmatically. Here is the screenshot for the same.
As you can see I have added two buttons to Reset and to Re-bind listbox again.
If I click on any of the button everything will work as expected but real problem is when we move scroll bar to bottom of the listbox and we re-bind listbox data.
See what kind of problem you shall face.
Solution :
Use scrolltoview function after assigning ItemsSource to listbox. See code snippet below.
List<ListBoxItem> a=GetItemsList(txt,count);
listbox1.ItemsSource = a;
if(a.Count()>0)
{
listbox1.UpdateLayout();
listbox1.ScrollIntoView(a[0]);
}
















