summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs105
1 files changed, 105 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs
new file mode 100644
index 00000000..0391ef4d
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1875.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Xamarin.Forms.CustomAttributes;
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve (AllMembers=true)]
+ [Issue (IssueTracker.Github, 1875, "NSRangeException adding items through ItemAppearing", PlatformAffected.iOS)]
+ public class Issue1875
+ : ContentPage
+ {
+ public Issue1875()
+ {
+ Button loadData = new Button { Text = "Load", HorizontalOptions = LayoutOptions.FillAndExpand };
+ ListView mainList = new ListView {
+ VerticalOptions = LayoutOptions.FillAndExpand,
+ HorizontalOptions = LayoutOptions.FillAndExpand
+ };
+
+ mainList.SetBinding (ListView.ItemsSourceProperty, "Items");
+
+ _viewModel = new MainViewModel ();
+ BindingContext = _viewModel;
+ loadData.Clicked += async (sender, e) => {
+ await LoadData ();
+ };
+
+ mainList.ItemAppearing += OnItemAppearing;
+
+ Content = new StackLayout {
+ Children = {
+ loadData,
+ mainList
+ }
+ };
+ }
+
+ readonly MainViewModel _viewModel;
+ int _start = 0;
+ const int NumberOfRecords = 15;
+
+ async void OnItemAppearing(object sender, ItemVisibilityEventArgs e)
+ {
+ var item = (int)e.Item;
+ if (!_viewModel.IsLoading && item == _viewModel.Items.Last())
+ await LoadData();
+ }
+
+ async Task LoadData ()
+ {
+ await _viewModel.LoadData (_start, NumberOfRecords);
+ _start = _start + NumberOfRecords;
+ }
+
+ public class MainViewModel : INotifyPropertyChanged
+ {
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public MainViewModel ()
+ {
+ }
+
+ ObservableCollection<int> _items;
+ public ObservableCollection<int> Items {
+ get {
+ if (_items == null)
+ _items = new ObservableCollection<int> ();
+
+ return _items;
+ }
+ set {
+ _items = value;
+ PropertyChanged (this, new PropertyChangedEventArgs ("Items"));
+ }
+ }
+
+ bool _isLoading;
+ public bool IsLoading {
+ get {
+ return _isLoading;
+ }
+ set {
+ if (_isLoading != value) {
+ _isLoading = value;
+ PropertyChanged (this, new PropertyChangedEventArgs ("IsLoading"));
+ }
+ }
+ }
+
+ public async Task LoadData (int start, int numberOfRecords)
+ {
+ IsLoading = true;
+ for (int counter = 0; counter < numberOfRecords; counter++)
+ Items.Add (start + counter);
+
+ IsLoading = false;
+ }
+ }
+ }
+} \ No newline at end of file