xaml - Scrollviewer ChangeView function not scrolling to bottom -


i have used listview inside scrollviewer in windows phone 8.1 rt app. have requirement of scrolling bottom of list change view function not working per requirement.

created sample same scenario:

mainpage.xaml

<page x:class="infilist.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:infilist" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:customlv="using:infilist" mc:ignorable="d" background="{themeresource applicationpagebackgroundthemebrush}"> <page.resources>     <style x:key="listviewstyle1" targettype="listview">         <setter property="istabstop" value="false"/>         <setter property="tabnavigation" value="once"/>         <setter property="isswipeenabled" value="true"/>         <setter property="horizontalcontentalignment" value="stretch"/>         <setter property="verticalcontentalignment" value="top"/>         <setter property="itemcontainertransitions">             <setter.value>                 <transitioncollection>                     <adddeletethemetransition/>                     <reorderthemetransition/>                 </transitioncollection>             </setter.value>         </setter>         <setter property="itemspanel">             <setter.value>                 <itemspaneltemplate>                     <itemsstackpanel orientation="vertical"/>                 </itemspaneltemplate>             </setter.value>         </setter>         <setter property="template">             <setter.value>                 <controltemplate targettype="listview">                     <border borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}">                         <itemspresenter footertransitions="{templatebinding footertransitions}" footertemplate="{templatebinding footertemplate}" footer="{templatebinding footer}" headertemplate="{templatebinding headertemplate}" header="{templatebinding header}" headertransitions="{templatebinding headertransitions}" horizontalalignment="{templatebinding horizontalcontentalignment}" padding="{templatebinding padding}" verticalalignment="{templatebinding verticalcontentalignment}"/>                     </border>                 </controltemplate>             </setter.value>         </setter>     </style> </page.resources>  <grid x:name="root">     <scrollviewer x:name="myscrollviewer" viewchanged="onviewchanged" isverticalscrollchainingenabled="true">         <listview x:name="listview" itemssource="{binding collection}" style="{staticresource listviewstyle1}" >             <listview.itemcontainerstyle>                 <style targettype="listviewitem">                     <setter property="horizontalcontentalignment" value="stretch"/>                     <setter property="verticalcontentalignment" value="stretch"/>                 </style>             </listview.itemcontainerstyle>              <listview.itemspanel>                 <itemspaneltemplate>                     <itemsstackpanel itemsupdatingscrollmode="keepitemsinview"/>                 </itemspaneltemplate>             </listview.itemspanel>             <listview.itemtemplate>                 <datatemplate>                     <grid background="lightgray" horizontalalignment="left" margin="25">                         <textblock margin="25 25 25 50" fontsize="32" text="{binding}" textwrapping="wrapwholewords" maxwidth="200"/>                     </grid>                  </datatemplate>             </listview.itemtemplate>         </listview>     </scrollviewer> </grid> <page.bottomappbar>     <commandbar>         <appbarbutton click="appbarbutton_click">          </appbarbutton>     </commandbar> </page.bottomappbar> 

mainpage.xaml.cs

using system; using system.collections.generic; using system.collections.objectmodel; using system.diagnostics; using system.io; using system.linq; using system.runtime.interopservices.windowsruntime; using windows.foundation; using windows.foundation.collections; using windows.ui.xaml; using windows.ui.xaml.controls; using windows.ui.xaml.controls.primitives; using windows.ui.xaml.data; using windows.ui.xaml.input; using windows.ui.xaml.media; using windows.ui.xaml.navigation;  // blank page item template documented @    http://go.microsoft.com/fwlink/?linkid=391641  namespace infilist { /// <summary> /// empty page can used on own or navigated within frame. /// </summary> public sealed partial class mainpage : page {      public observablecollection<string> collection { get; set; }      private bool incall;     private int offset;     int _noofelements;      public mainpage()     {         this.initializecomponent();         collection = new observablecollection<string>();         listview.datacontext = this;           this.navigationcachemode = navigationcachemode.required;          addnumber(0);         listview.loaded += listview_loaded;     }      void listview_loaded(object sender, routedeventargs e)     {         myscrollviewer.changeview(null, int.maxvalue, null, true);      }      private void onviewchanged(object sender, scrollviewerviewchangedeventargs e)     {         scrollviewer view = (scrollviewer)sender;         debug.writeline("vertica pffset: " + view.verticaloffset);          if ((view.verticaloffset < 0.1 * view.scrollableheight) & !incall)         {             incall = true;             addnumber(++offset);         }     }      private void addnumber(int offset)     {         int scrollcount = 30;         int start = offset * scrollcount;         (int = start; < start + scrollcount; i++)         {             string s= (_noofelements++).tostring() ;             if (i % 2 == 0)                 s += "msdkd kmsdksdk kdsmkd skmcds ckdsmckds ckdsmcksd kcmdskcdsc kdmmcsckdsc" + environment.newline + "sdjndsjnds"                     + "msdkd kmsdksdk kdsmkd skmcds ckdsmckds ckdsmcksd kcmdskcdsc kdmmcsckdsc" + environment.newline + "sdjndsjnds"                    + "dssdsddsds";              collection.insert(0,s);         }          incall = false;     }      /// <summary>     /// scrolls bottom     /// </summary>     /// <param name="sender"></param>     /// <param name="e"></param>     private void appbarbutton_click(object sender, routedeventargs e)     {         myscrollviewer.changeview(null, int.maxvalue, null, true);         //myscrollviewer.scrolltoverticaloffset(int.maxvalue);         //for scrolling till top         //myscrollviewer.scrolltoverticaloffset(0);     } } } 

is there way achieve desired functionality?

use scrollviewer's extentheight
scrollviewer.changeview(null, scrollviewer.extentheight, null);

sample: https://github.com/himanshpal/listviewvirtualizationtest


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -