summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs
blob: 896085a39e746a20bf8c6ba11b17f187080dff30 (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xamarin.Forms.Controls
{
	public class ButtonGallery : ContentPage
	{
		public ButtonGallery ()
		{
			BackgroundColor = new Color (0.9);

			var normal = new Button { Text = "Normal Button" };
			normal.Effects.Add (Effect.Resolve ("XamControl.BorderEffect"));

			var disabled = new Button { Text = "Disabled Button"};
			var disabledswitch = new Switch ();
			disabledswitch.SetBinding (Switch.IsToggledProperty, "IsEnabled");
			disabledswitch.BindingContext = disabled;

			var canTapLabel = new Label {
				Text = "Cannot Tap"
			};

			disabled.Clicked += (sender, e) => {
				canTapLabel.Text = "TAPPED!";
			};

			var click = new Button { Text = "Click Button" };
			var rotate = new Button { Text = "Rotate Button" };
			var transparent = new Button { Text = "Transparent Button" };
			string fontName;
			switch (Device.RuntimePlatform) {
			default:
			case Device.iOS:
				fontName = "Georgia";
				break;
			case Device.Android:
				fontName = "sans-serif-light";
				break;
			case Device.WinPhone:
			case Device.Windows:
				fontName = "Comic Sans MS";
				break;
			}

			var font = Font.OfSize (fontName, NamedSize.Medium);

			var themedButton = new Button {
				Text = "Accent Button",
				BackgroundColor = Color.Accent,
				TextColor = Color.White,
				ClassId = "AccentButton",
				Font = font
			};
			var borderButton = new Button {
				Text = "Border Button",
				BorderColor = Color.Black,
				BackgroundColor = Color.Purple,
				BorderWidth = 5,
				BorderRadius = 5
			};
			var timer = new Button { Text = "Timer" };
			var busy = new Button { Text = "Toggle Busy" };
			var alert = new Button { Text = "Alert" };
			var alertSingle = new Button {Text = "Alert Single"};
			var image = new Button { Text = "Image Button", Image = new FileImageSource {File = "bank.png"}, BackgroundColor = Color.Blue.WithLuminosity (.8) };

			themedButton.Clicked += (sender, args) => themedButton.Font = Font.Default;

			alertSingle.Clicked += (sender, args) => DisplayAlert ("Foo", "Bar", "Cancel");

			disabled.IsEnabled = false;
			int i = 1;
			click.Clicked += (sender, e) => { click.Text = "Clicked " + i++; };
			rotate.Clicked += (sender, e) => rotate.RelRotateTo (180);
			transparent.Opacity = .5;

			int j = 1;
			timer.Clicked += (sender, args) => Device.StartTimer (TimeSpan.FromSeconds (1), () => {
				timer.Text = "Timer Elapsed " + j++;
				return j < 4;
			});

			bool isBusy = false;
			busy.Clicked += (sender, args) => IsBusy = isBusy = !isBusy;

			alert.Clicked += async (sender, args) => {
				var result = await DisplayAlert ("User Alert", "This is a user alert. This is only a user alert.", "Accept", "Cancel");
				alert.Text = result ? "Accepted" : "Cancelled";
			};

			borderButton.Clicked += (sender, args) => borderButton.BackgroundColor = Color.Default;

			Content = new ScrollView {
				Content = new StackLayout {
					Padding = new Size (20, 20),
					Children = {
						normal,
						new StackLayout {
							Orientation = StackOrientation.Horizontal,
							Children={
								disabled,
								disabledswitch,
							},
						},
						canTapLabel,
						click,
						rotate,
						transparent,
						themedButton,
						borderButton,
						new Button {Text = "Thin Border", BorderWidth = 1, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black},
						new Button {Text = "Thinner Border", BorderWidth = .5, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black},
						new Button {Text = "BorderWidth == 0", BorderWidth = 0, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black},
						timer,
						busy,
						alert,
						alertSingle,
						image,
					}
				}
			};
				
		}
	}
}