Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PullToRefreshSamplePage.xaml.cs
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace PullToRefreshSampleApp
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
listView.ItemsSource = new ObservableCollection<int>(Enumerable.Range(1, 10));
}
private void scrollViewer_Loaded(object sender, RoutedEventArgs e)
{
scrollViewer.ChangeView(null, 60.0, null);
}
private void scrollViewer_SizeChanged(object sender, SizeChangedEventArgs e)
{
listView.Width = e.NewSize.Width;
listView.Height = e.NewSize.Height;
scrollViewer.ChangeView(null, 60.0, null);
}
bool _isPullRefresh = false;
private async void scrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
var sv = sender as ScrollViewer;
// text change
textBlock2.Opacity = sv.VerticalOffset / 100.0;
if (sv.VerticalOffset == 0.0)
textBlock1.Opacity = 0.7;
else
textBlock1.Opacity = 0.3;
if (sv.VerticalOffset != 0.0)
_isPullRefresh = true;
if (!e.IsIntermediate)
{
if (sv.VerticalOffset == 0.0 && _isPullRefresh)
{
// insert code...
var source = listView.ItemsSource as ObservableCollection<int>;
source.Add(source.Max() + 1);
await Task.Delay(300);
}
_isPullRefresh = false;
sv.ChangeView(null, 60.0, null);
}
}
}
}
@mslot

This comment has been minimized.

Copy link

@mslot mslot commented Feb 17, 2015

How would you handle orientation? Right now, if I go from portrait to landscape and back again, the "pull down to refresh"-part is always displayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment