summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/GalleryPages/AbsoluteLayoutGallery.cs
blob: 4c588ab9f1318a43ca4ee44989f36d42cf305152 (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	internal class AbsolutePositioningExplorationViewModel : INotifyPropertyChanged
	{
		double _rectangleX = 0.5;
		double _rectangleY = 0.5;
		double _rectangleWidth = 0.5;
		double _rectangleHeight = 0.5;

		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void OnPropertyChanged ([CallerMemberName] string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null)
				handler (this, new PropertyChangedEventArgs (propertyName));
		}

		public double RectangleX
		{
			get { return _rectangleX; }
			set
			{
				if (_rectangleX == value)
					return;
				_rectangleX = value;
				OnPropertyChanged ();
				OnPropertyChanged ("Rectangle");
			}
		}

		public double RectangleY
		{
			get { return _rectangleY; }
			set
			{
				if (_rectangleY == value)
					return;
				_rectangleY = value;
				OnPropertyChanged ();
				OnPropertyChanged ("Rectangle");
			}
		}

		public double RectangleWidth
		{
			get { return _rectangleWidth; }
			set
			{
				if (_rectangleWidth == value)
					return;
				_rectangleWidth = value;
				OnPropertyChanged ();
				OnPropertyChanged ("Rectangle");
			}
		}

		public double RectangleHeight
		{
			get { return _rectangleHeight; }
			set
			{
				if (_rectangleHeight == value)
					return;
				_rectangleHeight = value;
				OnPropertyChanged ();
				OnPropertyChanged ("Rectangle");
			}
		}

		public Rectangle Rectangle
		{
			get { return new Rectangle(RectangleX, RectangleY, RectangleWidth, RectangleHeight); }
		}
	}
	public class AbsoluteLayoutGallery : ContentPage
	{
		public AbsoluteLayoutGallery ()
		{
			if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
				Padding = new Thickness(0, 0, 0, 60);

			BindingContext = new AbsolutePositioningExplorationViewModel ();
			var absLayout = new AbsoluteLayout {
				BackgroundColor = Color.Gray,
				VerticalOptions = LayoutOptions.FillAndExpand
			};

			var rect = new BoxView {Color = Color.Lime};

			var xSlider = new Slider ();
			var ySlider = new Slider ();
			var widthSlider = new Slider ();
			var heightSlider = new Slider ();

			var grid = new Grid {
				Padding = 10,
				RowSpacing = 0,
				ColumnDefinitions = {
					new ColumnDefinition {Width = GridLength.Auto},
					new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)}
				}
			};

			grid.Children.Add (new Label {Text = "X:", VerticalTextAlignment = TextAlignment.Center}, 0, 0);
			grid.Children.Add (xSlider, 1, 0);
			
			grid.Children.Add (new Label {Text = "Y:", VerticalTextAlignment = TextAlignment.Center}, 0, 1);
			grid.Children.Add (ySlider, 1, 1);
			
			grid.Children.Add (new Label {Text = "Width:", VerticalTextAlignment = TextAlignment.Center}, 0, 2);
			grid.Children.Add (widthSlider, 1, 2);

			grid.Children.Add (new Label {Text = "Height:", VerticalTextAlignment = TextAlignment.Center}, 0, 3);
			grid.Children.Add (heightSlider, 1, 3);

			absLayout.Children.Add (rect);

			var mainLayout = new StackLayout {
				Spacing = 0,
				Children = {
					absLayout,
					grid
				}
			};

			rect.SetBinding (AbsoluteLayout.LayoutBoundsProperty, "Rectangle");
			AbsoluteLayout.SetLayoutFlags (rect, AbsoluteLayoutFlags.All);

			xSlider.SetBinding (Slider.ValueProperty, new Binding ("RectangleX", BindingMode.TwoWay));
			ySlider.SetBinding (Slider.ValueProperty, new Binding ("RectangleY", BindingMode.TwoWay));
			widthSlider.SetBinding (Slider.ValueProperty, new Binding ("RectangleWidth", BindingMode.TwoWay));
			heightSlider.SetBinding (Slider.ValueProperty, new Binding ("RectangleHeight", BindingMode.TwoWay));

			//Content = new ScrollView {Content = mainLayout};
			Content = mainLayout;
		}
	}
}