-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathViewModel.cs
67 lines (59 loc) · 2.01 KB
/
ViewModel.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
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using PullToRefresh;
namespace PullToRefresh {
public class ViewModel : INotifyPropertyChanged {
ProductData data;
bool isRefreshing = false;
public bool IsRefreshing {
get { return isRefreshing; }
set {
if (isRefreshing != value) {
isRefreshing = value;
OnPropertyChanged("IsRefreshing");
}
}
}
ObservableCollection<Product> products;
public ObservableCollection<Product> Products {
get { return products; }
set {
if (products != value) {
products = value;
OnPropertyChanged("Products");
}
}
}
ICommand pullToRefreshCommand = null;
public ICommand PullToRefreshCommand {
get { return pullToRefreshCommand; }
set {
if (pullToRefreshCommand != value) {
pullToRefreshCommand = value;
OnPropertyChanged("PullToRefreshCommand");
}
}
}
public ViewModel() {
this.data = new ProductData();
Products = data.Products;
PullToRefreshCommand = new Command(ExecutePullToRefreshCommand);
}
void ExecutePullToRefreshCommand() {
Task.Factory.StartNew(() => {
Thread.Sleep(3000);
Device.BeginInvokeOnMainThread(() => {
data.RefreshProducts();
Products = data.Products;
IsRefreshing = false;
});
});
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}