/
FirstViewModel.cs
76 lines (66 loc) · 1.6 KB
/
FirstViewModel.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
using System.Threading;
using System.Windows.Input;
using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;
namespace Lifecycle.Core.ViewModels
{
public interface IVisible
{
void IsVisible(bool isVisible);
}
public interface IKillable
{
void KillMe();
}
public abstract class BaseViewModel
: MvxViewModel
, IVisible
, IKillable
{
private Timer _timer;
public BaseViewModel()
{
_timer = new Timer(Callback, null, 0, 0);
}
private void Callback(object state)
{
Counter++;
}
private int _counter;
public int Counter
{
get { return _counter; }
set { _counter = value; RaisePropertyChanged(() => Counter); }
}
public void IsVisible(bool isVisible)
{
if (isVisible)
_timer.Change(1000,1000);
else
_timer.Change(0, 0);
}
public void KillMe()
{
Mvx.Trace("Killed: {0}", GetType().Name);
_timer.Dispose();
}
}
public class FirstViewModel
: BaseViewModel
{
public ICommand Go
{
get { return new MvxCommand(() => ShowViewModel<SecondViewModel>());}
}
}
public class SecondViewModel
: BaseViewModel
{
private string _hello = "Hello MvvmCross";
public string Hello
{
get { return _hello; }
set { _hello = value; RaisePropertyChanged(() => Hello); }
}
}
}