/
FirstView.cs
136 lines (115 loc) · 4.64 KB
/
FirstView.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System.Drawing;
using Cirrious.MvvmCross.Binding.BindingContext;
using Cirrious.MvvmCross.Touch.Views;
using Cirrious.MvvmCross.ViewModels;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using Tabbed.Core.ViewModels;
namespace Tabbed.Touch.Views
{
[Register("FirstView")]
public sealed class FirstView : MvxTabBarViewController
{
public FirstView()
{
// need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
ViewDidLoad();
}
protected FirstViewModel FirstViewModel
{ get { return base.ViewModel as FirstViewModel; } }
public override void ViewDidLoad()
{
base.ViewDidLoad();
// ios7 layout
if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
EdgesForExtendedLayout = UIRectEdge.None;
if (ViewModel == null)
return;
var viewControllers = new UIViewController[]
{
CreateTabFor("1", "home", FirstViewModel.Child1),
CreateTabFor("2", "twitter", FirstViewModel.Child2),
CreateTabFor("3", "favorites", FirstViewModel.Child3),
};
ViewControllers = viewControllers;
CustomizableViewControllers = new UIViewController[] { };
SelectedViewController = ViewControllers[0];
}
private int _createdSoFarCount = 0;
private UIViewController CreateTabFor(string title, string imageName, IMvxViewModel viewModel)
{
var controller = new UINavigationController();
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
SetTitleAndTabBarItem(screen, title, imageName);
controller.PushViewController(screen, false);
return controller;
}
private void SetTitleAndTabBarItem(UIViewController screen, string title, string imageName)
{
screen.Title = title;
screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle("Images/Tabs/" + imageName + ".png"),
_createdSoFarCount);
_createdSoFarCount++;
}
public void ShowGrandChild(IMvxTouchView view)
{
var currentNav = SelectedViewController as UINavigationController;
currentNav.PushViewController(view as UIViewController, true);
}
}
public class Child1View : MvxViewController
{
public override void ViewDidLoad()
{
View = new UIView() { BackgroundColor = UIColor.DarkGray};
base.ViewDidLoad();
NavigationItem.BackBarButtonItem = new UIBarButtonItem()
{
Title = "Kid1"
};
var label = new UILabel(new RectangleF(10, 10, 300, 40));
Add(label);
var button = new UIButton(UIButtonType.RoundedRect);
button.Frame = new RectangleF(10,50,300,40);
button.SetTitle("Go", UIControlState.Normal);
Add(button);
this.CreateBinding(label).To<Child1ViewModel>(vm => vm.Foo).Apply();
this.CreateBinding(button).To<Child1ViewModel>(vm => vm.GoCommand).Apply();
}
}
public class Child2View : MvxViewController
{
public override void ViewDidLoad()
{
View = new UIView() { BackgroundColor = UIColor.Magenta };
base.ViewDidLoad();
var label = new UILabel(new RectangleF(10, 10, 300, 40));
Add(label);
this.CreateBinding(label).To<Child2ViewModel>(vm => vm.Bar).Apply();
}
}
public class Child3View : MvxViewController
{
public override void ViewDidLoad()
{
View = new UIView() { BackgroundColor = UIColor.Orange };
base.ViewDidLoad();
var label = new UILabel(new RectangleF(10, 10, 300, 40));
Add(label);
this.CreateBinding(label).To<Child3ViewModel>(vm => vm.Oink).Apply();
}
}
public class GrandChildView : MvxViewController
{
public override void ViewDidLoad()
{
View = new UIView() { BackgroundColor = UIColor.Red };
base.ViewDidLoad();
Title = "Grand Child";
var label = new UILabel(new RectangleF(10, 10, 300, 40));
Add(label);
this.CreateBinding(label).To<GrandChildViewModel>(vm => vm.Life).Apply();
}
}
}