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

namespace Xamarin.Forms.Controls
{

	public class GridGallery : ContentPage
	{
		public GridGallery ()
		{
			var layout = new StackLayout { 
				Orientation = StackOrientation.Vertical
			};

			//ColumnTypes
			layout.Children.Add (new Label { Text = "Column Types:" });
			var grid = new Grid { 
				ColumnDefinitions = {
					new ColumnDefinition { Width = 80 },
					new ColumnDefinition (),
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }
				},
				BackgroundColor = Color.FromRgb (0xee, 0xee, 0xee)
			};

			grid.Children.Add (new Label { 
				Text = "Absolute Width",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 0, 0);
			grid.Children.Add (new Label { 
				Text = "Auto Width",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 1, 0);
			grid.Children.Add (new Label { 
				Text = "Star",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 2, 0);
			layout.Children.Add (grid);

			//Star
			layout.Children.Add (new Label { Text = "Star Columns:" });
			grid = new Grid { 
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (2, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (3, GridUnitType.Star) },
				},
				BackgroundColor = Color.FromRgb (0xee, 0xee, 0xee),
				ColumnSpacing = 0,
				RowSpacing = 0,
			};

			grid.Children.Add (new Label { 
				Text = "*",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 0, 0);
			grid.Children.Add (new Label { 
				Text = "**",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 1, 0);
			grid.Children.Add (new Label { 
				Text = "***",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
			}, 2, 0);
			layout.Children.Add (grid);

			//Alignment
			layout.Children.Add (new Label { Text = "Alignment:" });
			grid = new Grid { 
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				},
				BackgroundColor = Color.FromRgb (0xee, 0xee, 0xee)
			};

			grid.Children.Add (new Label { 
				Text = "Right",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
				HorizontalOptions = LayoutOptions.End,
			}, 0, 0);
			grid.Children.Add (new Label { 
				Text = "Center",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
				HorizontalOptions = LayoutOptions.Center,

			}, 1, 0);
			grid.Children.Add (new Label { 
				Text = "Left",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
				HorizontalOptions = LayoutOptions.Start,
			}, 2, 0);
			grid.Children.Add (new Label { 
				Text = "Fill",
				BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
				HorizontalOptions = LayoutOptions.Fill,
			}, 3, 0);
			layout.Children.Add (grid);

			//Spanning
			layout.Children.Add (new Label { Text = "Spans:" });
			grid = new Grid { 
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
				},
				BackgroundColor = Color.FromRgb (0xee, 0xee, 0xee),
				ColumnSpacing = 0,
				RowSpacing = 0
			};

			for (var i=0;i<5;i++)
				for (var j=0;j<5;j++)
					grid.Children.Add (new Label { 
						Text = "Unit",
						BackgroundColor = Color.FromRgb (0xcc, 0xcc, 0xcc),
					}, i, j);


			grid.Children.Add (new Label { 
				Text = "Spanning 4 columns",
				BackgroundColor = Color.Red,
			}, 0,4,0,1);
			grid.Children.Add (new Label { 
				Text = "Spanning 3 rows",
				BackgroundColor = Color.Gray,
			}, 4,5, 0,3);
			grid.Children.Add (new Label { 
				Text = "a block 3x3",
				BackgroundColor = Color.Green,
			}, 1,4,1,4);
			layout.Children.Add (grid);


			//Change Width
			var col0 = new ColumnDefinition { Width = 40 };
			var col1 = new ColumnDefinition { Width = 80 };

			grid = new Grid {
				ColumnDefinitions = new ColumnDefinitionCollection {
					col0, col1
				}
			};

			grid.Children.Add (new BoxView { BackgroundColor = Color.Red });
			grid.Children.Add (new BoxView { BackgroundColor = Color.Blue },1,0);

			layout.Children.Add (grid);
			layout.Children.Add (new Button { 
				Text = "ChangeWidth",
				Command = new Command (()=>{
					var t = col0.Width;
					col0.Width = col1.Width;
					col1.Width = t;
				})
			});

			Content = new ScrollView {
				Content = layout,
			};



		}
	}
}