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
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xamarin.Forms.Controls
{
public class LayoutOptionsGallery : ContentPage
{
public LayoutOptionsGallery ()
{
Build ();
}
void Build ()
{
var mainLayout = new StackLayout {
BackgroundColor = Color.Silver,
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {
BuildLayoutRegion (),
BuildLayoutRegion ()
}
};
var changeOrientationButton = new Button {Text = "Change Orientation"};
changeOrientationButton.Clicked += (sender, args) => mainLayout.Orientation = (mainLayout.Orientation == StackOrientation.Horizontal) ? StackOrientation.Vertical : StackOrientation.Horizontal;
Content = new StackLayout {
Children = {
changeOrientationButton,
mainLayout
}
};
}
LayoutOptions StringToLayoutOptions (string options)
{
switch (options) {
case "Start":
return LayoutOptions.Start;
case "StartAndExpand":
return LayoutOptions.StartAndExpand;
case "Center":
return LayoutOptions.Center;
case "CenterAndExpand":
return LayoutOptions.CenterAndExpand;
case "End":
return LayoutOptions.End;
case "EndAndExpand":
return LayoutOptions.EndAndExpand;
case "Fill":
return LayoutOptions.Fill;
case "FillAndExpand":
return LayoutOptions.FillAndExpand;
}
throw new InvalidDataException ();
}
View BuildLayoutRegion ()
{
// Set these to fill and expand so they just fill their parent which is the thing we actually want to play with.
var horizontalButton = new Button {
Text = "H Options",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
var verticalButton = new Button {
Text = "V Options",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
var result = new StackLayout {
BackgroundColor = Color.Gray,
Children = {
horizontalButton,
verticalButton
}
};
horizontalButton.Clicked += async (sender, args) => {
var selection = await DisplayActionSheet ("Select Horizontal Options", null, null,
"Start", "StartAndExpand",
"Center", "CenterAndExpand",
"End", "EndAndExpand",
"Fill", "FillAndExpand");
result.HorizontalOptions = StringToLayoutOptions (selection);
};
verticalButton.Clicked += async (sender, args) => {
var selection = await DisplayActionSheet ("Select Horizontal Options", null, null,
"Start", "StartAndExpand",
"Center", "CenterAndExpand",
"End", "EndAndExpand",
"Fill", "FillAndExpand");
result.VerticalOptions = StringToLayoutOptions (selection);
};
return result;
}
}
}
|