-
Notifications
You must be signed in to change notification settings - Fork 3
/
TemplatesForXamarinStudio.cs.txt
315 lines (225 loc) · 6.5 KB
/
TemplatesForXamarinStudio.cs.txt
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
The templates below are useful when creating code based applications with Xamarin.Forms. You will be able to quickly create and prototype
a Xamarin.Forms application in a very short amount of time. To add the templates, you will need to open Preferences from Xamarin Studio's main
menu, select the "Text Editor" section, followed by the Code Templates. You will need to add each template individually. I have added my
suggested name for each comment so that I can hit xf and then the templates start to appear
// ** TEMPLATE: xfAbsoluteLayout ** //
var $name$ = new AbsoluteLayout();
// Add the items with their locations
$name$.Children.Add($control$, new Point(20, 20));
// ** TEMPLATE: xfAlert ** //
var $name$ = await page.DisplayAlert("$title$", "$message$", "OK", "Cancel");
// ** TEMPLATE: xfBox ** //
var $name$ = new BoxView()
{
WidthRequest = $width$,
HeightRequest = $height$,
BackgroundColor = Color.Silver
};$END$
// ** TEMPLATE: xfButton ** //
var $name$ = new Button() {
Text = "$END$"
};
$name$.Clicked += (s, e) => {
};
// ** TEMPLATE: xfCarousel ** //
var $name$ = new CarouselPage()
{
Children = {
new ContentPage(),
new ContentPage()
}
};
// ** TEMPLATE: xfControlProperty ** //
public static readonly BindableProperty $PropertyName$Property = BindableProperty.Create<ImageInfoBlock, $DataType$>(p => p.$PropertyName$, default($DataType$));
public $DataType$ $PropertyName$
{
get
{
return ($DataType$)base.GetValue($PropertyName$Property);
}
set
{
base.SetValue ($PropertyName$Property, value);
}
}
// ** TEMPLATE: xfCustomCell ** //
public class $name$Cell : ViewCell
{
public $name$Cell()
{
// Create the custom controls
var $labelName$ = new Label()
{
Text = "$END$"
};
var layout = new StackLayout()
{
Padding = new Thickness(20, 0, 0, 0),
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.StartAndExpand,
Children = { $labelName$ }
};
View = layout;
}
}
// ** TEMPLATE: xfDatePicker ** //
var $name$ = new DatePicker() { $END$ };
// TEMPLATE: xfDependancyGet ** //
var $service$ = DependencyService.Get<$servicename$>();
// ** TEMPLATE: xfDependancyRegister ** //
[assembly: Dependency(typeof($classname$))]$END$
// ** TEMPLATE: xfDeviceOnAndroid ** //
Device.OnPlatform(
Android: () => { },
Default: () => { }
);
// ** TEMPLATE: xfDeviceOnPlatform ** //
Device.OnPlatform(
iOS: () => { },
Android: () => { },
WinPhone: () => { }
);
// ** TEMPLATE: xfDeviceOnWinPhone ** //
Device.OnPlatform(
WinPhone: () => { },
Default: () => { });
// ** TEMPLATE: xfDeviceOniOS ** //
Device.OnPlatform(
iOS: () => { },
Default: () => { }
);
// ** TEMPLATE: xfEntry ** //
var $name$ = new Entry() { Placeholder = "$END$" };
// ** TEMPLATE: xfImage ** //
var $name$ = new Image() {
Source = FileImageSource.FromFile ("$END$")
};
// ** TEMPLATE: xfLabel ** //
var $name$ = new Label() {
Text = "$END$"
};
// ** TEMPLATE: xfLabelEntry ** //
var $name$Label = new Label()
{
Text = "$name$"
};
var $name$Entry = new Entry() {Placeholder = "$name$"};
// ** TEMPLATE: xfListViewContentPage ** //
public class $name$Page : ContentPage
{
public $name$Page()
{
var listView = new ListView
{
ItemsSource = new String[] { },
ItemTemplate = new DataTemplate(typeof (TextCell))
{
Bindings =
{
{TextCell.TextProperty, new Binding(".")},
//{TextCell.DetailProperty, new Binding(".")}
}
}
};
listView.ItemSelected += (s, e) => {
var item = e.SelectedItem;
// Deal with the item
};
Content = listView;
}
}
// ** TEMPLATE: xfMapPage ** //
public class $name$ : ContentPage
{
public $name$()
{
Title = "$title$";
var map = new Map(new MapSpan(new Position(30.26535, ‐97.738613),
0.05, 0.05))
{
MapType = MapType.Street,
HeightRequest = 508
};
Pin pin;
map.Pins.Add(pin = new Pin() {
Label = "$pintitle$",
Position = new Position(30.26535, ‐97.738613),
Type = PinType.Place
});
Content = new StackLayout() {
VerticalOptions = LayoutOptions.StartAndExpand,
Children = { map }
};
}
}
// ** TEMPLATE: xfMapsInitAndroid ** //
Xamarin.FormsMaps.Android.Xamarin.FormsMaps.Init(this, bundle);
// ** TEMPLATE: xfMapsInitiOS ** //
Xamarin.FormsMaps.iOS.Xamarin.FormsMaps.Init();
// ** TEMPLATE: xfMasterDetailPage ** //
var $name$ = new MasterDetailPage()
{
Master = new $masterpage$(),
Detail = new $detailpage$()
};
// ** TEMPLATE: xfMessagingCenterSend ** //
MessagingCenter.Send(this, "$messagename$", $item$);
// ** TEMPLATE: xfMessagingCenterSubscribe ** //
MessagingCenter.Subscribe(this, "$messagename$"",
(object sender, object item) => {
// Typecast the objects to what you expect
});
// ** TEMPLATE: xfNavigationPage ** //
var $name$ = new NavigationPage(new $rootpage$());
// ** TEMPLATE: xfSearchBar ** //
var $name$ = new SearchBar() { Placeholder = "Search for..." };
$name$.SearchButtonPressed += (sender, args) =>
{
$END$
};
// ** TEMPLATE: xfStackedLayoutHorizontal ** //
var $name$ = new StackLayout()
{
VerticalOptions = LayoutOptions.End,
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.Start,
Padding = new Thickness(20),
Children = {
// Add the controls underneath here
$END$
}
};
// ** TEMPLATE: xfStackedContentPage ** //
public class $name$Page : ContentPage
{
public $name$Page()
{
// Create the controls here
Content = new StackLayout()
{
VerticalOptions = LayoutOptions.StartAndExpand,
Padding = new Thickness(20),
Children = {
// Add the controls underneath here
}
};
}
}
// ** TEMPLATE: xfSwitch ** //
var $name$ = new Switch();
// ** TEMPLATE: xfTapGesture ** //
var $name$ = new TapGestureRecognizer(view => {
// What to do when the item is tapped
$END$
}) { NumberOfTapsRequired = 1 };
$control$.GestureRecognizers.Add($name$);
// ** TEMPLATE: xfTimePicker ** //
var $name$ = new TimePicker() { $END$ };
// ** TEMPLATE: xfWebView ** //
var $source$ = new UrlWebViewSource ();
$source$.Url = "http://$url$";
var $name$ = new WebView {
WidthRequest = 300,
HeightRequest = 400
};
$name$.Source = $source$;