Skip to content

Instantly share code, notes, and snippets.

@ideaki
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideaki/54f04dbaa02e6f4c937a to your computer and use it in GitHub Desktop.
Save ideaki/54f04dbaa02e6f4c937a to your computer and use it in GitHub Desktop.
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
Copy link

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