Background
Many times in the process of doing WP development will encounter data needs paging acquisition, according to Microsoft's official recommendation, proposed to achieve a similar experience in market, that is, sliding to the bottom of the list to load more data.
This demand in the early WP7.1 time to realize is very laborious, need to rely on WP Toolkit in the longlistselector, and since the LLS by Microsoft after the need to achieve a more official method.
"The realization of ideas"
LLS inherits the features of the ListBox UI virtualization, where data from UI virtualization--a list data source--does not itemtemplete all data at once, but as the list slides, it is either UI at any time, or the UI data is released. For example, the more intuitive:
For example, the LLS data source has a 1W user type of data, which records users ' information. LLS is responsible for displaying the 1W data. Suppose a screen can display 10. So the job of UI virtualization is to:
1, 30 (for example data) user based on Itemtemplete to draw the corresponding 30 UI controls
2, slide down to see the 20th data, from the data source to take out 20 draw UI control, and the first 20 of the drawing out of the control released.
3, slide down to see the 40th data, and then take out the data source 20 draw UI control, and the first 20 drawn out of the control released.
4, to slide back to the 20th data, reverse again to draw and release
The concept of UI virtualization above is understood and the requirements in our headlines are well implemented.
LLS defines the onitemrealized event, which simply says that when Lls draws a UI control based on Itemtemplete, it triggers this event to notify the user of which data is currently being drawn.
"Specific Code Analysis"
The code we implement according to this definition is as follows:
Explain:
1, offset is the distance from the last item in the data source
2, IsLoading is the dependency property, identity is currently loading data
3. When the Onitemrealized event is triggered, determine whether the current realized item is the penultimate item of the data source, and if so, it is considered necessary to load new data, triggering the Datarequest event
Such a simple universal "endless list" is implemented.
See more highlights of this column: http://www.bianceng.cn/OS/extra/
Reference:
Http://msdn.microsoft.com/library/windowsphone/develop/microsoft.phone.controls.longlistselector.itemrealized ( v=vs.105). aspx
http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e
See the complete code:
https://gist.github.com/tianhonghui/6999984