Microsoft has integrated the Longlistselector in WP8, but the control is not implemented in ViewModel Selectdeitem bidirectional binding, because it is not DependencyProperty no way can only implement the extension!
1. Implement the Longlistselector extension extendedselector
public enum Positiononadd {Top, Default, newitem} public class Extendedselector:longli Stselector {public static readonly DependencyProperty Selecteditemproperty = Dependencyproperty.regi Ster ("SelectedItem", typeof (Object), typeof (Extendedselector), new PropertyMetadata (Default (object))); public static readonly DependencyProperty Selectionmodeproperty = Dependencyproperty.register ("SelectionMode", typeof (SelectionMode), typeof (Extendedselector), New PropertyMetadata (Selectionmode.single)); public static readonly DependencyProperty Repositiononaddstyleproperty = Dependencyproperty.register ("Repositio Nonaddstyle ", typeof (Positiononadd), typeof (Extendedselector), New PropertyMetadata (Positiononadd.default)); Public Positiononadd Repositiononaddstyle {get {return (Positiononadd) GetValue (Repositiononaddstylepro Perty); } set {SetValue (RepositiononaddstylepropertY, value); }} public SelectionMode SelectionMode {get {return (SelectionMode) GetValue (selectionmod Eproperty); } set {SetValue (Selectionmodeproperty, value);} } Public new Object SelectedItem {get {return GetValue (selecteditemproperty);} set {SetValue (Selecteditemproperty, value);} } public Extendedselector () {selectionchanged + = (sender, args) = { if (SelectionMode = = selectionmode.single) SelectedItem = args. Addeditems[0]; else if (SelectionMode = = selectionmode.multiple) {if (SelectedItem = = null) {SelectedItem = new list<object> (); } foreach (var item in args. Addeditems) {((list<object>) SelectedItem). ADD (item); } foreach (Var removeditem in args. Removeditems) {if ((list<object>) SelectedItem). Contains (Removeditem)) {((list<object>) SelectedItem). Remove (Removeditem); } } } }; Loaded + = (sender, args) = {((inotifycollectionchanged) ItemsSource). CollectionChanged + = (sender2, args2) = {if (itemssource.count > 0 && ar Gs2. NewItems! = null) {switch (Repositiononaddstyle) { Case PositionOnAdd.NewItem:int index = Itemssource.indexof (ARGS2. Newitems[0]); if (index >= 0) ScrollTo (Itemssource[index]); Break Case PositionOnAdd.Top:ScrollTo (itemssource[0]); Break } } }; }; } }
2. Using the extended extendedselector in Xmal
A. Defining a data template
<datatemplate x:name= "Llsdatatemplate" > <listboxitem margin= "0,0,0,6" > <StackPanel> <stackpanel margin= "0,0,0,12" > <textblock toolkit:slideineffect.lineindex= "1" Foreground= "{StaticResource Fontgroundthemebrush}" textwrapping= "Wrap" fontsize= "" " texttrimming=" None " text=" {Binding name} " /> <textblock toolkit:slideineffect.lineindex=" 2 "foreground=" {StaticResource Fontgroundthemebrush} "opacity=" 0.7 "textwrapping=" Wrap "texttrimming=" None " fontsize=" 18 " text= "{Binding content}" /> </StackPanel> </StackPanel> </ListBoxItem> </DataTemplate>
B. Defining the style of Longlistselector
<style x:key= "Jumpliststyle" targettype= "Phone:longlistselector" > <setter property= "GridCellSize" Value= "111,111"/> <setter property= "LayoutMode" value= "Grid"/> <setter property= "Margin" value= "18,12 , 0,0 "/> <setter property=" ItemTemplate "> <Setter.Value> <DATATEMPLATE&G T <border background= "{Binding converter={staticresource Backgroundconverter}}" margin= "6" > &L T TextBlock text= "{Binding Key}" fontfamily= "{StaticResource phonefontfamilysemibold}" Fontsize= "padding=" 11,0,0,1 "foreground=" {Binding Converter={staticresource Foregroundconverter}} "verticalalignment=" Bottom "/> </border& Gt </DataTemplate> </Setter.Value> </Setter> </Style> <DataTemplate x:key= "Groupheadertemplate" > <border background= "Transparent" padding= "5" > <bor Der Background= "{StaticResource Backgroundthemebrush}" borderbrush= "{StaticResource Backgroundthemebrus H} "width=" "height=" "margin=" -6,0,18,6 " Horizontalalignment= "Left" > <textblock text= "{Binding Key}" foreground= "{S Taticresource Phoneforegroundbrush} "fontsize=" padding= "6,6,6,11" Fontfamily= "{StaticResource phonefontfamilysemilight}" horizontalalign Ment= "left" verticalalignment= "Center"/> </Border> </Border> </DataTemplate>
Implementation of C.page page code
<control:extendedselector margin= "12,0,12,24" x:name= "Reaultlistbox" Itemsso Urce= "{Binding searchreaultitem, Mode=twoway}" selecteditem= "{Binding Selectcydqitem , mode=twoway} "groupheadertemplate=" {StaticResource groupheadertemplate} " Hideemptygroups= "true" isgroupingenabled= "true" Itemtemplate= "{StaticResource llsdatatemplate}" toolk it:turnstilefeathereffect.featheringindex= "1" jumpliststyle= "{StaticResource Jumplis Tstyle} "repositiononaddstyle=" Top "> <i:inter Action. triggers> <i:eventtrigger eventname= "SelectionChanged" > <Cmd:eventtocommand command= "{Binding searchvm.selectionchangedcommand,source={staticresource Locator}}" Commandparameter= "{Binding path=selecteditem,elementname=reaultlistbox}"/> </i:ev Enttrigger> </i:interaction. Triggers> </control:ExtendedSelector>
Implementation results:
Description: repositiononaddstyle= "Top" has top,default,newitem, top for loading data after the display from the beginning of the head newitem to load the data after the display from the tail start
The longlistselector extension in WindowsPhone8 solves the problem that it cannot bind Selectdeitem