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
|
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.TestCasesPages
{
[Preserve (AllMembers=true)]
[Issue (IssueTracker.Github, 2270, "NSInternalCOnsistencyException when bound to ObservableCollection", PlatformAffected.iOS)]
public class Issue2270 : ContentPage
{
public Issue2270()
{
BindingContext = new TestListViewModel();
Padding = new Thickness(0, 40, 0, 0);
var btn = new Button {
Text = "Load Data",
BorderWidth = 1,
BorderColor = Color.Gray,
};
btn.SetBinding (Button.CommandProperty, "LoadDataCommand");
var lv = new ListView();// { IsGroupingEnabled = true };
var dt = new DataTemplate (typeof(TextCell));
dt.SetBinding (TextCell.TextProperty, "Name");
lv.ItemTemplate = dt;
lv.SetBinding (ListView.ItemsSourceProperty, "Rows");
Content = new StackLayout {
Children = {
btn,
lv
}
};
}
public class TestListViewModel
{
//public ObservableCollection<ObservableCollection<Row>> Rows {
public ObservableCollection<Row> Rows {
get;
set;
}
public TestListViewModel ()
{
//Rows = new ObservableCollection<ObservableCollection<Row>>();
Rows = new ObservableCollection<Row>();
}
Command _command;
public Command LoadDataCommand {
get {
return _command ?? (_command = new Command (LoadData));
}
}
void LoadData() {
Rows.Clear ();
foreach (var row in new[] { new Row { Name = "one" }, new Row { Name = "Two" } }) {
Rows.Add (row);
}
}
}
public class Row
{
public string Name { get; set; }
}
}
}
|