Recently in a dynamic list (like QQ space), have not found ready to let me to pick up, can only go to work, found a little difficulty with the listbox, changed the Longlistselector, but longlistselector see write pull loading not satisfied, The reference to a few articles themselves wrote a, to see the effect of the first
Here's how to do it, the XAML code (the Longlistselector style doesn't pass, just adjusts his UI):
<local:viewmodel x:key="ViewModel"/> <datatemplate x:key="Listheader"> <Grid> <image source="/image/Rectangle -6.png"/> <image source="/image/Layer -1.png"height="113"Width="113"Horizontalalignment=" Left"margin="30,80,0,0"/> <textblock text="Small slot June"Fontsize=" -"Foreground="#333334"Verticalalignment="Center"Horizontalalignment="Center"margin="0,30,50,0"/> <textblock text="25 years old"Fontsize=" A"Foreground="#545455"Verticalalignment="Center"Horizontalalignment="Center"margin="0,120,10,0"/> <image width=" A"Verticalalignment="Center"Horizontalalignment="Center"Source="/image/Vector Smart Object-copy -9.png"margin="0,120,110,0"/> </Grid> </DataTemplate> <datatemplate x:key="itemTemplate"> <grid height=" -"Background=" White"margin="10,0,10,10"> <textblock text="{Binding}"Foreground="#494949"Fontsize=" -"margin="123,0,0,0"/> <image source="/image/Layer -1.png"height="113"Verticalalignment="Top"Horizontalalignment=" Left"/> </Grid> </DataTemplate> <datatemplate x:key="Listfooter"> <textblock text="Loading in ..."Horizontalalignment="Center"Fontsize=" A"/> </datatemplate><grid datacontext="{StaticResource ViewModel}"Background="#494949"> <phone:longlistselector name="lls"Itemssource="{Binding List}"listheadertemplate="{StaticResource Listheader}"ItemTemplate="{StaticResource ItemTemplate}"listfootertemplate="{StaticResource Listfooter}"Style="{StaticResource LongListSelectorStyle1}"> <i:interaction. triggers> <local:ScrollBarTrigger> <i:invokecommandaction command="{Binding Moreitemcommand}"/> </local:ScrollBarTrigger> </i:interaction. Triggers> </phone:LongListSelector> </Grid>
Here using Longlistselector's listheadertemplate to make a head, listfootertemplate do a pull down the bottom of the loading state (you can add an animation), using triggers to do a sliding trigger event, To execute a command.
Below is the key code for a pull-up load (the others are inside the source)
Public classScrollbartrigger:triggerbase<dependencyobject>{ScrollBar ScrollView; Public EventEventHandler Scrolltrigger; protected Override voidonattached () {Base. Onattached (); if( This. Associatedobject! =NULL&& This. Associatedobject isFrameworkElement) { ( This. Associatedobject asFrameworkElement). SizeChanged + =control_sizechanged; } } protected Override voidondetaching () {Base. Ondetaching (); if(ScrollView! =NULL) scrollview.valuechanged-=scrollview_valuechanged; if( This. Associatedobject! =NULL&& This. Associatedobject isFrameworkElement) { ( This. Associatedobject asFrameworkElement). SizeChanged-=control_sizechanged; } } voidControl_sizechanged (Objectsender, Sizechangedeventargs e) { if( This. Associatedobject = =NULL|| ! ( This. Associatedobject isFrameworkElement)) return; ScrollBar Scroll= This. Associatedobject.getfirstdescendantoftype<scrollbar>(); if(Scroll! =NULL) {attachedscroll (Scroll); ( This. Associatedobject asFrameworkElement). SizeChanged-=control_sizechanged; } } voidAttachedscroll (ScrollBar Scroll) {if(Scroll! =NULL) {ScrollView=Scroll; Scrollview.valuechanged+=scrollview_valuechanged; } } voidScrollview_valuechanged (Objectsender, routedpropertychangedeventargs<Double>e) {onoffsetchanged (); } voidonoffsetchanged () {if(ScrollView = =NULL) return; ScrollBar Scroll=ScrollView; if(Scroll.viewportsize = =0|| Scroll.value + $<scroll.maximum)return; if(Scrolltrigger! =NULL) {Scrolltrigger ( This. Associatedobject,NewEventArgs ()); } Base. Invokeactions (NULL); } }
Pull-up loading is mainly to obtain Longlistselector scrollbar, by judging the current sliding value of scrollbar and the range can be determined by the maximum sliding value comparison to determine whether the end of the bottom, to reach the base with the Invokeactions trigger Association event so it is finished.
Worry about the destruction of the virtualization of children, I have tested, do not worry, but also want to further achieve, such as friends to restore your dynamic or how to insert into the list, I provide ideas (the code is not given, but also from their own project stripping down too much trouble), One can be in your ItemTemplate inside set a behavior to add ah, stupid way in the inside in a ListBox, you can also use groupfootertemplate this is still relatively useful
Source: http://download.csdn.net/detail/qq593295212/8428635
WP8 with Longlistselector do List (can QQ friends dynamic, micro-blog list of various places), add pull-up loading