Getting Started with UWP Development (vii)--drop-down refresh

Source: Internet
Author: User

This article is intended to give these days Win10 Mobile Negative news constantly a soft wash, want to prove to achieve a simple drop-down refresh is not difficult. The greater difficulty with UWP development is laziness, lack of willingness to learn. Instead of the idea of "a soft-connected dropdown refresh control does not have".

I did not have a pull-down refresh study before. So first went to Google a few blog study a bit, and then looked at a soft official Sample. (Students Ah, the official have to pull the refreshed Sample Ah!) It's on Git ! No money, no threshold! After learning, there are basically two kinds of ways to realize it.

sample< Span lang= "ZH-CN" > and blog Park ms-uap encapsulated pulltorefreshboxlistview Scrollviewscrollviewscrollview viewchanged events to load new data. Once you have finished loading the new data, move the release refresh area up again to hide it.

The other is to get the ScrollView inside the ListView by attaching properties and detect the related manpulation events of the internal ScrollView to implement data refresh.

Consider that the attached property is slightly out of reach, and the first class of code can be simpler to write. Therefore, the use of ScrollView nested method, give a minimalist pull-down refresh implementation, although not all the requirements, but considering the amount of code in the line, absolutely you deserve!

The first is the code of the XAML, and there are no advanced tricks:

    <GridBackground="{ThemeResource Applicationpagebackgroundthemebrush}">                <ScrollViewerx:name= "ScrollViewer"Loaded= "scrollviewer_loaded"viewchanged= "Scrollviewer_viewchanged">            <StackPanelOrientation= "Vertical">                <progressringIsActive="{x:bind Ispullrefresh,mode=oneway}"Height= "+"></progressring>                <ListViewx:name= "List"ItemsSource="{x:bind Items}" ></ListView>            </StackPanel>                    </ScrollViewer>    </Grid>

Then look at the CS file. The first is the definition of the Items and Ispullrefresh properties, which are datasets in the ListView, which binds to progressring the IsActive property, which is omitted here, is not a table.

It is noteworthy that onlyscrollviewer_loaded and scrollviewer_viewchanged two methods. scrollviewer load method, in the initial state we will Span lang= "en-US" >scrollviewer scroll up 30pxprogressring hidden up. Then scrollviewer_viewchangedisintermediate progressringscrollviewer scroll up 30px hide progressring

     Public Sealed Partial classMainpage:page, INotifyPropertyChanged { Publicobservablecollection<Object> Items {Get;Set; }  Public BOOLIspullrefresh {Get            {                return_ispullrefresh; }            Set{_ispullrefresh=value;            OnPropertyChanged (nameof (Ispullrefresh)); }        }        BOOL_ispullrefresh =false;  PublicMainPage () { This.            InitializeComponent (); Items=Newobservablecollection<Object>();  for(inti =0; I < +; i++) {items.add (i); }        }         Public EventPropertyChangedEventHandler propertychanged;  Public voidOnPropertyChanged (stringname) {             This. PropertyChanged?. Invoke ( This,NewPropertyChangedEventArgs (name)); }        Private voidScrollviewer_loaded (Objectsender, RoutedEventArgs e) {Scrollviewer.changeview (NULL, -,NULL); }        Private Async voidScrollviewer_viewchanged (Objectsender, Scrollviewerviewchangedeventargs e) {            varSV = Sender asScrollViewer; if(!e.isintermediate) {                if(SV. Verticaloffset = =0.0) {Ispullrefresh=true; awaitTask.delay ( -);  for(inti =0; I <5; i++) {Items.insert (0, i); } sv. ChangeView (NULL, -,NULL); } Ispullrefresh=false; }        }    }

Do you think it's easy to finish the call? This is the case with UWP development, which is hard indeed, and experience does not. Compared to the relatively mature IOS and Android Development, is the need for more sweat and effort. But is Microsoft going to fall? Is Microsoft's technology not promising? is Windows ten waste? If you are free to search the internet without eggs, it is better to learn more.

continue to advertise, this Scrollviewer nested listviewlistview control itself scrollviewer Sliding conflict, and cannot pinpoint listviewitem

Microsoft /Windows-universal-samples

Getting Started with UWP Development (vii)--drop-down refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.