blob: 4ca08fcfab3343684769827485a3238a34c1aa3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
using System;
using Xamarin.Forms.CustomAttributes;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 30651, "ListView jumps around while scrolling after items are added to its source")]
public class Bugzilla30651: TestContentPage
{
ListViewModel _viewModel;
protected override void Init ()
{
_viewModel = new ListViewModel();
BindingContext = _viewModel;
var lv = new ListView ();
lv.SetBinding (ListView.ItemsSourceProperty, new Binding ("Items"));
lv.SeparatorVisibility = SeparatorVisibility.None;
lv.HasUnevenRows = true;
lv.ItemAppearing+= (object sender, ItemVisibilityEventArgs e) => {
_viewModel.OnItemAppearing(e.Item.ToString());
};
lv.ItemTemplate = new DataTemplate (typeof(TestCell));
Content = lv;
}
public class TestCell : ViewCell {
Label _myLabel;
public TestCell ()
{
View = _myLabel = new Label();
}
protected override void OnBindingContextChanged()
{
if (BindingContext == null)
return;
var i = BindingContext as string;
_myLabel.Text = i;
Height = 100;
base.OnBindingContextChanged();
}
}
public class ListViewModel : ViewModelBase
{
ObservableCollection<string> _items;
int _counter = 0;
public ObservableCollection<string> Items
{
get { return _items; }
set { _items = value; OnPropertyChanged ();}
}
public ListViewModel()
{
Items = new ObservableCollection<string>();
AddMoreData();
}
public void OnItemAppearing(string s)
{
if (Items.Last() == s)
AddMoreData();
}
void AddMoreData()
{
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
_counter++;
Items.Add(_counter.ToString());
}
}
}
}
|