-
Notifications
You must be signed in to change notification settings - Fork 182
/
UpdateItemsPageModel.cs
92 lines (75 loc) · 1.78 KB
/
UpdateItemsPageModel.cs
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
using System;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Xamarin.Forms;
using Xamvvm;
namespace DLToolkitControlsSamples
{
public class UpdateItemsPageModel : BasePageModel
{
static int insertId = 0;
public UpdateItemsPageModel()
{
ItemTappedCommand = new BaseCommand((param) =>
{
var item = LastTappedItem as SimpleItem;
if (item != null)
System.Diagnostics.Debug.WriteLine("Tapped {0}", item.Title);
});
AddCommand = new BaseCommand((arg) =>
{
insertId++;
Items.Insert(10, new SimpleItem() { Title = string.Format("New {0}", insertId) });
});
RemoveCommand = new BaseCommand((arg) =>
{
Items.RemoveAt(10);
});
}
public ObservableCollection<object> Items
{
get { return GetField<ObservableCollection<object>>(); }
set { SetField(value); }
}
public void ReloadData()
{
var exampleData = new ObservableCollection<object>();
var howMany = new Random().Next(100, 500);
for (int i = 0; i < howMany; i++)
{
exampleData.Add(new SimpleItem() { Title = string.Format("Item nr {0}", i) });
}
Items = exampleData;
}
public ICommand ItemTappedCommand
{
get { return GetField<ICommand>(); }
set { SetField(value); }
}
public ICommand AddCommand
{
get { return GetField<ICommand>(); }
set { SetField(value); }
}
public ICommand RemoveCommand
{
get { return GetField<ICommand>(); }
set { SetField(value); }
}
public object LastTappedItem
{
get { return GetField<object>(); }
set { SetField(value); }
}
public class SimpleItem : BaseModel
{
string title;
public string Title
{
get { return title; }
set { SetField(ref title, value); }
}
public Color Color { get; private set; } = Colors.RandomColor;
}
}
}