The list of data that is commonly used in WINRT is Listbox,listview,gridview. In the application, sometimes the user browses for a long time
After the list content wants to go back to the top of the list, what can be done about this requirement?
The most important thing is to take advantage of the scrollIntoView method of the list control.
OK, don't say anything, the code is as follows.
Xaml:
<page x:class= "Dragdemo.blankpage1" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local= "Using:dragdemo" xmlns:d= "http// schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/ 2006 "mc:ignorable=" D "background=" {ThemeResource Applicationpagebackgroundthemebrush} "> <Grid> & Lt grid.rowdefinitions> <rowdefinition height= "80*"/> <rowdefinition height= "20*"/> </Grid.RowDefinitions> <grid grid.row= "0" > <listview x:name= "ListView" > <ListView.Items> <ListViewItem> <textblock text= "AAAA" Fontsi Ze= "/> </ListViewItem> <ListViewItem> <t Extblock text= "aaaa" fontsize= "/>" </ListViewItem> <ListViewItem> <textblock text= "AAAA" Fontsi Ze= "/> </ListViewItem> <ListViewItem> <t Extblock text= "aaaa" fontsize= "/> </ListViewItem> <ListViewItem> <textblock text= "aaaa" fontsize= "/> </ListViewItem> <ListViewItem> <textblock text= "aaaa" fontsize= "/> </list" viewitem> <ListViewItem> <textblock text= "aaaa" fontsize= "/>" </ListViewItem> <ListViewItem> <textblock text= "AAAA" fontsize= "/> </ListViewItem> <ListViewItem>" <textblock Text= "aaaa" fontsize= "/>" </ListViewItem> <ListViewItem> <textblock text= "aaaa" fontsize= "/> </ListViewItem> <li" stviewitem> <textblock text= "aaaa" fontsize= "/> </listviewitem>" ; <ListViewItem> <textblock text= "aaaa" fontsize= "/> </listviewi" tem> <ListViewItem> <textblock text= "aaaa" fontsize= "/>" </ListViewItem> <ListViewItem> <textblock text= "AAAA "Fontsize="/> </ListViewItem> <ListViewItem> <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewit" em&Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewitem&" Gt <textblock text= "aaaa" fontsize= "/> </listviewit"em> <ListViewItem> <textblock text= "aaaa" fontsize= "/>" </ListViewItem> <ListViewItem> <textblock text= "AAAA" Fontsize= "/> </ListViewItem> <ListViewItem>" <textblock text= "aaaa" fontsize= "/> </ListViewItem> <listviewite" m> <textblock text= "aaaa" fontsize= "/>" </ListViewItem> </ListView.Items> </ListView> </Grid> <canvas grid.row= "1" > <border x:name= "Border" width= "[]" "Height=" cornerradius= "" "Background=" Coral "tapped=" border_tapped "> <textblock text= "Back to Top" horizontalalignment= "center" verticalalignment= "center" fontsize= "/>" </Border> </Canvas> </Grid></Page>
. Cs:
Using system;using system.collections.generic;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 in http://go.microsoft.com/fwlink/? linkid=390556 on the namespace dragdemo{////<summary>//////for self or to navigate to a blank page inside the Frame. </summary> public sealed partial class Blankpage1:page {public BlankPage1 () { This. InitializeComponent (); }///<summary>///This page will be called when it is displayed in Frame. </summary>//<param name= "E" > Describes how to access event data for this page. This parameter is typically used for configuration pages. </param> protected override void Onnavigatedto (NavigationEventArgs e) {} private void B order_tapped (obJect sender, Tappedroutedeventargs e) {var item = ListView. Items.firstordefault (); if (item!=null) {listview. scrollIntoView (item); } } }}
This allows you to click Back to the top of the list of features, in fact, the code is very simple.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
WINRT back to the top of the list feature