c# - Performance lag in scrollTo function for LongListSelector in WP8? -
to demonstrate problem here code behind code
public partial class mainpage : phoneapplicationpage { observablecollection<abc> listtest = new observablecollection<abc>(); // constructor public mainpage() { initializecomponent(); (int = 0; < 50; i++) { abc conv = new abc(string.format("test:{0}", i)); listtest.add(conv); } testlls.itemssource = listtest; } private void button_tap_1(object sender, system.windows.input.gestureeventargs e) { testlls.scrollto(listtest[listtest.count - 1]); } private void titlepanel_tap_1(object sender, system.windows.input.gestureeventargs e) { stopwatch st = stopwatch.startnew(); testlls.scrollto(listtest[listtest.count - 1]); st.stop(); debug.writeline("tttt:", st.elapsedmilliseconds); } class abc { private string _name; public abc(string aa) { this._name = aa; } public string name { { return _name; } } public visibility groupmembervisibility { { return visibility.collapsed; } } } }
xaml code
<stackpanel x:name="titlepanel" grid.row="0" margin="12,17,0,28" tap="titlepanel_tap_1"> <textblock text="my application" style="{staticresource phonetextnormalstyle}" margin="12,0"/> <textblock text="page name" margin="9,-7,0,0" style="{staticresource phonetexttitle1style}"/> </stackpanel> <!--contentpanel - place additional content here--> <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0"> <phone:longlistselector name="testlls" virtualizingstackpanel.virtualizationmode="standard" > <phone:longlistselector.itemtemplate> <datatemplate x:name="dtrecievedbubbletext" > <grid x:name="layoutroot" background="transparent" margin="24 0 0 14" horizontalalignment="left"> <grid.rowdefinitions> <rowdefinition height="14" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <grid grid.row="1"> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition height="auto" /> <rowdefinition height="auto" /> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="auto"/> </grid.columndefinitions> <rectangle grid.rowspan="3" fill="{binding bubblebackgroundcolor}" /> <textblock text="test" visibility="{binding groupmembervisibility}" fontsize="22" fontfamily="segoe wp semibold" margin="12, 12, 0, 0" /> <textblock grid.row="2" text="{binding name}" horizontalalignment="right" margin="0,0,12,6" fontsize="18" /> </grid> </grid> </datatemplate> </phone:longlistselector.itemtemplate> </phone:longlistselector> </grid>
on tapping header long list selector containg elemnts scrolls bottom. when value of elements changed 30-50-100 elements time observed 20ms, 744ms, 815ms. testing done nokia lumia 620.
in sample, item template simple in real scenario item templates more complex
. , time taken in scenario 1753ms 100 elements
.
why such huge time difference
. can improved
in way?
has else observed this?
there workaround fix issue.
extract viewport lls , set viewport origin.
to extract viewport have add style in xaml
<style x:name="llsmessagesstyle" targettype="phone:longlistselector"> <setter property="background" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="phone:longlistselector"> <grid background="{templatebinding background}" d:designwidth="480" d:designheight="800"> <visualstatemanager.visualstategroups> <visualstategroup x:name="scrollstates"> <visualstategroup.transitions> <visualtransition generatedduration="00:00:00.5"/> </visualstategroup.transitions> <visualstate x:name="scrolling"> <storyboard> <doubleanimation duration="0" to="1" storyboard.targetproperty="opacity" storyboard.targetname="verticalscrollbar"/> </storyboard> </visualstate> <visualstate x:name="notscrolling"/> </visualstategroup> </visualstatemanager.visualstategroups> <grid margin="0"> <viewportcontrol x:name="viewportcontrol" horizontalcontentalignment="stretch" verticalalignment="bottom" loaded="viewportloaded"/> <scrollbar x:name="verticalscrollbar" style="{staticresource chatthemescrollbarstyle}" opacity="0" margin="2 0 2 0" orientation="vertical" horizontalalignment="right" width="5" valuechanged="vscrollbar1_valuechanged" /> </grid> </grid> </controltemplate> </setter.value> </setter> </style>
in code behind:
viewportcontrol llsviewport; private void viewportloaded(object sender, routedeventargs e) { llsviewport = sender viewportcontrol; } private void scrolltobottom() { if (llsviewport != null) llsviewport.setviewportorigin(new system.windows.point(0, llsviewport.bounds.height)); }
in way can achieve desired functionality.
Comments
Post a Comment