summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs
blob: 18276d814b06224f7ae92633f743d8b956eda487 (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
175
176
177
178
179
180
181
182
using System;
using Xamarin.Forms;

namespace Xamarin.Forms.Controls
{
	internal class ScaleRotate : ContentPage
	{
		public ScaleRotate()
		{
			Label label = new Label
			{
				Text = "SCALE AND\nROTATE",
				HorizontalTextAlignment = TextAlignment.Center,
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.CenterAndExpand
			};

			// Label and Slider for Scale property.
			Label scaleSliderValue = new Label
			{
				VerticalTextAlignment = TextAlignment.Center
			};
			Grid.SetRow(scaleSliderValue, 0);
			Grid.SetColumn(scaleSliderValue, 0);

			Slider scaleSlider = new Slider
			{
				Maximum = 10
			};
			Grid.SetRow(scaleSlider, 0);
			Grid.SetColumn(scaleSlider, 1);

			// Set Bindings.
			scaleSliderValue.BindingContext = scaleSlider;
			scaleSliderValue.SetBinding(Label.TextProperty, 
				new Binding("Value", BindingMode.OneWay, null, null, "Scale = {0:F1}"));

			scaleSlider.BindingContext = label;
			scaleSlider.SetBinding(Slider.ValueProperty,
				new Binding("Scale", BindingMode.TwoWay));

			// Label and Slider for ScaleX property.
			Label scaleXSliderValue = new Label {
				VerticalTextAlignment = TextAlignment.Center
			};
			Grid.SetRow(scaleXSliderValue, 1);
			Grid.SetColumn(scaleXSliderValue, 0);

			Slider scaleXSlider = new Slider {
				Maximum = 10
			};
			Grid.SetRow(scaleXSlider, 1);
			Grid.SetColumn(scaleXSlider, 1);

			// Set Bindings.
			scaleXSliderValue.BindingContext = scaleXSlider;
			scaleXSliderValue.SetBinding(Label.TextProperty,
				new Binding("Value", BindingMode.OneWay, null, null, "ScaleX = {0:F1}"));

			scaleXSlider.BindingContext = label;
			scaleXSlider.SetBinding(Slider.ValueProperty,
				new Binding("ScaleX", BindingMode.TwoWay));

			// Label and Slider for Rotation property.
			Label rotationSliderValue = new Label
			{
				VerticalTextAlignment = TextAlignment.Center
			};
			Grid.SetRow(rotationSliderValue, 2);
			Grid.SetColumn(rotationSliderValue, 0);

			Slider rotationSlider = new Slider
			{
				Maximum = 360
			};
			Grid.SetRow(rotationSlider, 2);
			Grid.SetColumn(rotationSlider, 1);

			// Set Bindings.
			rotationSliderValue.BindingContext = rotationSlider;
			rotationSliderValue.SetBinding(Label.TextProperty,
				new Binding("Value", BindingMode.OneWay, null, null, "Rotation = {0:F0}"));

			rotationSlider.BindingContext = label;
			rotationSlider.SetBinding(Slider.ValueProperty,
				new Binding("Rotation", BindingMode.TwoWay));

			// Label and Slider for AnchorX property.
			Label anchorxStepperValue = new Label
			{
				VerticalTextAlignment = TextAlignment.Center
			};
			Grid.SetRow(anchorxStepperValue, 3);
			Grid.SetColumn(anchorxStepperValue, 0);

			Stepper anchorxStepper = new Stepper
			{
				Maximum = 2,
				Minimum = -1,
				Increment = 0.5
			};
			Grid.SetRow(anchorxStepper, 3);
			Grid.SetColumn(anchorxStepper, 1);

			// Set bindings.
			anchorxStepperValue.BindingContext = anchorxStepper;
			anchorxStepperValue.SetBinding(Label.TextProperty,
				new Binding("Value", BindingMode.OneWay, null, null, "AnchorX = {0:F1}"));

			anchorxStepper.BindingContext = label;
			anchorxStepper.SetBinding(Stepper.ValueProperty, 
				new Binding("AnchorX", BindingMode.TwoWay));

			// Label and Slider for AnchorY property.
			Label anchoryStepperValue = new Label
			{
				VerticalTextAlignment = TextAlignment.Center
			};
			Grid.SetRow(anchoryStepperValue, 4);
			Grid.SetColumn(anchoryStepperValue, 0);

			Stepper anchoryStepper = new Stepper
			{
				Maximum = 2,
				Minimum = -1,
				Increment = 0.5
			};
			Grid.SetRow(anchoryStepper, 4);
			Grid.SetColumn(anchoryStepper, 1);

			// Set bindings.
			anchoryStepperValue.BindingContext = anchoryStepper;
			anchoryStepperValue.SetBinding(Label.TextProperty,
				new Binding("Value", BindingMode.OneWay, null, null, "AnchorY = {0:F1}"));

			anchoryStepper.BindingContext = label;
			anchoryStepper.SetBinding(Stepper.ValueProperty, 
				new Binding("AnchorY", BindingMode.TwoWay));

			// Assemble the page.
			Content = new StackLayout
			{
				Children =
				{
					label,
					new Grid
					{
						Padding = 10,
						RowDefinitions = 
						{
							new RowDefinition { Height = GridLength.Auto },
							new RowDefinition { Height = GridLength.Auto },
							new RowDefinition { Height = GridLength.Auto },
							new RowDefinition { Height = GridLength.Auto },
							new RowDefinition { Height = GridLength.Auto },
						},
						ColumnDefinitions = 
						{
							new ColumnDefinition { Width = GridLength.Auto },
							new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)}
						},
						Children = 
						{
							scaleSliderValue,
							scaleSlider,
							scaleXSliderValue,
							scaleXSlider,
							rotationSliderValue,
							rotationSlider,
							anchorxStepperValue, 
							anchorxStepper,
							anchoryStepperValue,
							anchoryStepper
						}
					}
				}
			};
		}
	}
}