Universal Windows Platform 下拉更新(使用NuGet包)

除了使用ScrollViewer实现下来更新,也可以使用第三方的NuGet包实现该效果。
NuGet包名:PullToRefresh.UWP.
Github: https://github.com/MS-UAP/PullToRefresh.UWP

Xaml code:

 xmlns:pr="using:PullToRefresh.UWP"//先添加命名空间

<!--将listView放在PullToRefreshBox中-->
 <pr:PullToRefreshBox x:Name="pr" RefreshInvoked="PullToRefreshBox_RefreshInvoked">
            <ListView x:Name="lsitView" ItemsSource="{x:Bind Items}" />
        </pr:PullToRefreshBox>

CS code:

public ObservableCollection<object> Items { get; set; }

//实现PullToRefreshBox_RefreshInvoked事件,注意参数类型
 private void PullToRefreshBox_RefreshInvoked(DependencyObject sender,object e)
        {
            if (Items.Count > 7)
            {
                Items.Clear();
            }
            else
            {
                Random r = new Random();
                Items.Insert(0, r.Next());
            }
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s