If a large amount of data is bound to The ListBox control, loading is usually slow, there is an interactive solution to optimize this situation, that is, loading part of the data on the ListBox first, some data will be loaded when you scroll down The ListBox to the end. However, there are no related events or attributes in The ListBox control to determine when the ListBox is rolled to the end. The following describes a solution. The ListBox control encapsulates the scrollviewer control and scrollbar control. This is easy to handle. You can obtain the scrollviewer control encapsulated in the ListBox control, and then determine whether the ListBox control is rolled to the end through the attributes of the scrollviewer control. Next let's take a look. Code :
< Grid X: Name = "Contentpanel" Grid. Row = "1" Margin = "12, 0, 12, 0" >
< ListBox Name = "Listbox1" Mousemove = "Listbox#mousemove" >
</ ListBox >
</ Grid >
Using System;
Using System. Collections. Generic;
Using System. windows;
Using System. Windows. controls;
Using System. Windows. input;
Using System. Windows. Media;
Using Microsoft. Phone. controls;
Namespace Listboxupdate
{
Public Partial Class Mainpage: phoneapplicationpage
{
Public Mainpage ()
{
Initializecomponent ();
For ( Int I = 0 ; I < 30 ; I ++ )
{
Listbox1.items. Add ( " Project " + I );
}
}
Private Void Listbox1_mousemove ( Object Sender, mouseeventargs E)
{
// Obtain the subtype scrollviewer of ListBox
Scrollviewer = Findchildoftype < Scrollviewer > (Listbox1 ); // Scrollviewer scrollbar
If (Scrollviewer = Null )
{
Throw New Invalidoperationexception ( " Erro " );
}
Else
{
// Determines whether the current rolling height is greater than or equal to the actual rolling height of scrollviewer.
If (Scrollviewer. verticaloffset > = Scrollviewer. scrollableheight)
{
// Handling ListBox scrolling to the end
For ( Int I = 0 ; I < 10 ; I ++ )
{
Int K = Listbox1.items. count;
Listbox1.items. Add ( " Project " + K );
K ++ ;
}
}
}
}
// Obtain child types
Static T findchildoftype < T > (Dependencyobject root) Where T: Class
{
VaR queue = New Queue < Dependencyobject > ();
Queue. enqueue (Root );
While (Queue. Count > 0 )
{
Dependencyobject current = Queue. dequeue ();
For ( Int I = Visualtreehelper. getchildrencount (current) - 1 ; 0 <= I; I -- )
{
VaR child = Visualtreehelper. getchild (current, I );
VaR typedchild = Child As T;
If (Typedchild ! = Null )
{
Return Typedchild;
}
Queue. enqueue (child );
}
}
Return Null ;
}
}
}
Running Effect Do you have any better solutions ??? Below there is a person recommended to use an extended ListBox control lazylistbox, find the blog link: http://blogs.msdn.com/ B /ptorr/archive/2010/10/12/procrastination-ftw-lazylistbox-should-improve-your-scrolling-performance-and-responsiveness.aspx