-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSamplePageInCode.cs
More file actions
157 lines (131 loc) · 4.3 KB
/
SamplePageInCode.cs
File metadata and controls
157 lines (131 loc) · 4.3 KB
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
using System;
using Xamarin.Forms;
using Programmation.Xam.Graphics2D;
using System.Diagnostics;
namespace Graphics2D
{
public class SamplePageInCode
: ContentPage
{
private Slider _beerSlider;
private Graphic _beerView;
private Button _actionButton;
private Graphic _logoView;
private StackLayout _mainView;
private ScrollView _scrollView;
private double _startSliderValue = 1.0;
public SamplePageInCode ()
{
_beerSlider = CreateBeerSlider ();
_beerView = CreateBeerView ();
_actionButton = CreateActionButton ();
_logoView = CreateLogoView ();
var scrolling = true;
if (scrolling) {
_scrollView = new ScrollView ();
}
_mainView = new StackLayout {
BackgroundColor = Color.FromRgb (200, 200, 200),
VerticalOptions = LayoutOptions.Center,
Padding = new Thickness (0, 20, 0, 0),
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!",
TextColor = Color.White,
},
_beerSlider,
_beerView,
_actionButton,
_logoView,
},
};
if (scrolling) {
_scrollView.Content = _mainView;
Content = _scrollView;
} else {
Content = _mainView;
}
Content.BackgroundColor = Color.FromRgb (235, 235, 235);
}
private Slider CreateBeerSlider ()
{
var slider = new Slider {
HorizontalOptions = LayoutOptions.Center,
Minimum = 0.3,
Maximum = 2.0,
Value = _startSliderValue,
};
slider.ValueChanged += HandleBeerSliderUpdate;
return slider;
}
private void HandleBeerSliderUpdate (object sender, ValueChangedEventArgs e)
{
// _mapMarker.ScaleTo (_beerSlider.Value);
_beerView.ScaleTo (_beerSlider.Value);
// Logger.WriteLine ("{2} Before ForceLayout: HR{0:N}->H{1:N}", _logoView.HeightRequest, _logoView.Height, _logoView.GraphicSource);
// _scrollView.ForceLayout ();
// Logger.WriteLine ("{2} After ForceLayout: HR{0:N}->H{1:N}", _logoView.HeightRequest, _logoView.Height, _logoView.GraphicSource);
}
private Graphic CreateBeerView ()
{
var view = Graphic.FromBuilder ("BeerIcon", _beerSlider.Value);
view.HorizontalOptions = LayoutOptions.Center;
return view;
}
private Button CreateActionButton ()
{
var button = new Button {
Text = "Hide",
TextColor = Color.White,
Font = Font.SystemFontOfSize (25, FontAttributes.Bold),
};
button.Clicked += HandleActionButtonClicked;
return button;
}
private async void HandleActionButtonClicked (object sender, EventArgs e)
{
_actionButton.IsEnabled = false;
if (_mainView.Children.Contains (_logoView)) {
await _logoView.FadeTo (0, easing: Easing.CubicOut).ConfigureAwait (true);
_mainView.Children.Remove (_logoView);
_actionButton.Text = "Show";
} else {
_mainView.Children.Add (_logoView);
await _logoView.FadeTo (1, easing: Easing.CubicIn).ConfigureAwait (true);
_actionButton.Text = "Hide";
}
_actionButton.IsEnabled = true;
_scrollView.ForceLayout ();
}
private Graphic CreateLogoView ()
{
var view = Graphic.FromBuilder ("Logo");
view.BackColor = Color.White;
// BUG: If WidthRequest is -1 or > screen width, Height is not preserved after the first ForceLayout() call
// If WidthRequest <= screen width all works fine
var showBug = false;
if (showBug) {
view.WidthRequest = 500;
view.HorizontalOptions = LayoutOptions.CenterAndExpand;
view.ScalingMode = GraphicViewScalingMode.PreserveAspect;
} else {
// view.WidthRequest = 200;
view.HorizontalOptions = LayoutOptions.Center;
}
// view.HeightRequest = 85;
return view;
}
protected override SizeRequest OnSizeRequest (double widthConstraint, double heightConstraint)
{
var sizeRequest = base.OnSizeRequest (widthConstraint, heightConstraint);
Logger.WriteLine ("{0} OnSizeRequest = [WC{1:N}, HC{2:N}]->[WRW{7:N},HRH{8:N}], WR{3:N}->W{4:N}, HR{5:N}->H{6:N}", "Page", widthConstraint, heightConstraint, WidthRequest, Width, HeightRequest, Height, sizeRequest.Request.Width, sizeRequest.Request.Height);
return sizeRequest;
}
protected override void OnSizeAllocated (double width, double height)
{
Logger.WriteLine ("{0} OnSizeAllocated = [WA{1:N},HA{2:N}], WR{3:N}->W{4:N}, HR{5:N}->H{6:N}", "Page", width, height, WidthRequest, Width, HeightRequest, Height);
base.OnSizeAllocated (width, height);
}
}
}