@@ -11,112 +11,121 @@ public class ScrollGallery : ContentPage
11
11
readonly ScrollView _scrollview ;
12
12
readonly StackLayout _stack ;
13
13
ScrollOrientation _orientation ;
14
- List < Button > _buttons = new List < Button > ( ) ;
14
+ List < Button > _buttons = new List < Button > ( ) ;
15
15
Button _toNavigateTo ;
16
- public ScrollGallery ( ScrollOrientation orientation = ScrollOrientation . Vertical )
16
+ public ScrollGallery ( ScrollOrientation orientation = ScrollOrientation . Vertical )
17
17
{
18
18
_orientation = orientation ;
19
- var root = new Grid ( ) ;
20
- root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
21
- root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
22
- root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
23
- root . RowDefinitions . Add ( new RowDefinition ( ) ) ;
19
+ var root = new Grid ( ) ;
20
+ root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
21
+ root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
22
+ root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
23
+ root . RowDefinitions . Add ( new RowDefinition ( ) { Height = GridLength . Auto } ) ;
24
+ root . RowDefinitions . Add ( new RowDefinition ( ) ) ;
24
25
25
26
var btnStack1 = new StackLayout { Orientation = StackOrientation . Horizontal } ;
26
- var btnStack = new StackLayout { Orientation = StackOrientation . Horizontal } ;
27
+ var btnStack2 = new StackLayout { Orientation = StackOrientation . Horizontal } ;
28
+ var btnStack3 = new StackLayout { Orientation = StackOrientation . Horizontal } ;
29
+
27
30
var btn = new Button { Text = "Scroll to 100" } ;
28
31
var btn4 = new Button { Text = "Scroll to 100 no anim" } ;
29
32
var btn1 = new Button { Text = "Start" } ;
30
33
var btn2 = new Button { Text = "Center" } ;
31
34
var btn3 = new Button { Text = "End" } ;
32
- var btn7 = new Button { Text = "Toggle Scroll Bar Visibility" } ;
33
- var btn6 = new Button { Text = "MakeVisible" , HorizontalOptions = LayoutOptions . CenterAndExpand , BackgroundColor = Color . Accent } ;
34
- var btn8 = new Button { Text = "Toggle Orientation" } ;
35
- var btn9 = new Button { Text = "Default Scroll Bar Visibility" } ;
35
+ var btn7 = new Button { Text = "Toggle Scroll Bar Visibility" , WidthRequest = 120 } ;
36
+ var btn6 = new Button { Text = "MakeVisible" , HorizontalOptions = LayoutOptions . CenterAndExpand , BackgroundColor = Color . Accent } ;
37
+ var btn8 = new Button { Text = "Toggle Orientation" , WidthRequest = 120 } ;
38
+ var btn9 = new Button { Text = "Default Scroll Bar Visibility" , WidthRequest = 120 } ;
36
39
37
40
var labelStack = new StackLayout { Orientation = StackOrientation . Horizontal } ;
38
- var label = new Label { Text = string . Format ( "X: {0}, Y: {1}" , 0 , 0 ) } ;
41
+ var label = new Label { Text = string . Format ( "X: {0}, Y: {1}" , 0 , 0 ) } ;
39
42
var scrollStatusLabel = new Label { Text = string . Empty } ;
40
-
41
- root . Children . Add ( labelStack ) ;
42
- root . Children . Add ( btnStack ) ;
43
- root . Children . Add ( btnStack1 ) ;
44
43
45
- btnStack . Children . Add ( btn1 ) ;
46
- btnStack . Children . Add ( btn2 ) ;
47
- btnStack . Children . Add ( btn3 ) ;
48
- btnStack . Children . Add ( btn7 ) ;
49
- btnStack . Children . Add ( btn9 ) ;
50
- btnStack . Children . Add ( btn8 ) ;
44
+ root . Children . Add ( labelStack ) ;
45
+ root . Children . Add ( btnStack1 ) ;
46
+ root . Children . Add ( btnStack2 ) ;
47
+ root . Children . Add ( btnStack3 ) ;
48
+
49
+ btnStack1 . Children . Add ( btn1 ) ;
50
+ btnStack1 . Children . Add ( btn2 ) ;
51
+ btnStack1 . Children . Add ( btn3 ) ;
52
+
53
+ btnStack2 . Children . Add ( btn ) ;
54
+ btnStack2 . Children . Add ( btn4 ) ;
51
55
52
- btnStack1 . Children . Add ( btn ) ;
53
- btnStack1 . Children . Add ( btn4 ) ;
56
+ btnStack3 . Children . Add ( btn7 ) ;
57
+ btnStack3 . Children . Add ( btn9 ) ;
58
+ btnStack3 . Children . Add ( btn8 ) ;
54
59
55
60
labelStack . Children . Add ( label ) ;
56
61
labelStack . Children . Add ( scrollStatusLabel ) ;
57
62
58
- Grid . SetRow ( btnStack , 1 ) ;
59
- Grid . SetRow ( btnStack1 , 2 ) ;
60
-
61
- var grid = new Grid ( ) ;
62
- grid . RowDefinitions . Add ( new RowDefinition { Height = GridLength . Auto } ) ;
63
- grid . RowDefinitions . Add ( new RowDefinition ( ) ) ;
64
- _stack = new StackLayout ( ) ;
65
- Grid . SetRow ( _stack , 1 ) ;
66
- grid . Children . Add ( btn6 ) ;
67
- grid . Children . Add ( _stack ) ;
68
- _scrollview = new ScrollView {
69
- AutomationId = "thescroller" ,
63
+ Grid . SetRow ( btnStack1 , 1 ) ;
64
+ Grid . SetRow ( btnStack2 , 2 ) ;
65
+ Grid . SetRow ( btnStack3 , 3 ) ;
66
+
67
+ var grid = new Grid ( ) ;
68
+ grid . RowDefinitions . Add ( new RowDefinition { Height = GridLength . Auto } ) ;
69
+ grid . RowDefinitions . Add ( new RowDefinition ( ) ) ;
70
+ _stack = new StackLayout ( ) ;
71
+ Grid . SetRow ( _stack , 1 ) ;
72
+ grid . Children . Add ( btn6 ) ;
73
+ grid . Children . Add ( _stack ) ;
74
+ _scrollview = new ScrollView
75
+ {
76
+ AutomationId = "thescroller" ,
70
77
BackgroundColor = Color . Aqua ,
71
78
Content = grid
72
79
} ;
73
- root . Children . Add ( _scrollview ) ;
74
- Grid . SetRow ( _scrollview , 3 ) ;
80
+ root . Children . Add ( _scrollview ) ;
81
+ Grid . SetRow ( _scrollview , 4 ) ;
75
82
76
- _scrollview . Scrolled += ( object sender , ScrolledEventArgs e ) => {
77
- label . Text = string . Format ( "X: {0}, Y: {1}" , e . ScrollX , e . ScrollY ) ;
83
+ _scrollview . Scrolled += ( object sender , ScrolledEventArgs e ) => {
84
+ label . Text = string . Format ( "X: {0}, Y: {1}" , e . ScrollX , e . ScrollY ) ;
78
85
} ;
79
86
80
87
btn . Clicked += async ( object sender , EventArgs e ) => {
81
88
scrollStatusLabel . Text = "scrolling" ;
82
- switch ( orientation ) {
89
+ switch ( orientation )
90
+ {
83
91
case ScrollOrientation . Horizontal :
84
- await _scrollview . ScrollToAsync ( 100 , 0 , true ) ;
92
+ await _scrollview . ScrollToAsync ( 100 , 0 , true ) ;
85
93
break ;
86
94
case ScrollOrientation . Vertical :
87
- await _scrollview . ScrollToAsync ( 0 , 100 , true ) ;
95
+ await _scrollview . ScrollToAsync ( 0 , 100 , true ) ;
88
96
break ;
89
97
case ScrollOrientation . Both :
90
- await _scrollview . ScrollToAsync ( 100 , 100 , true ) ;
98
+ await _scrollview . ScrollToAsync ( 100 , 100 , true ) ;
91
99
break ;
92
100
}
93
101
scrollStatusLabel . Text = "completed" ;
94
102
} ;
95
103
btn4 . Clicked += async ( object sender , EventArgs e ) => {
96
- switch ( orientation ) {
104
+ switch ( orientation )
105
+ {
97
106
case ScrollOrientation . Horizontal :
98
- await _scrollview . ScrollToAsync ( 100 , 0 , false ) ;
107
+ await _scrollview . ScrollToAsync ( 100 , 0 , false ) ;
99
108
break ;
100
109
case ScrollOrientation . Vertical :
101
- await _scrollview . ScrollToAsync ( 0 , 100 , false ) ;
110
+ await _scrollview . ScrollToAsync ( 0 , 100 , false ) ;
102
111
break ;
103
112
case ScrollOrientation . Both :
104
- await _scrollview . ScrollToAsync ( 100 , 100 , true ) ;
113
+ await _scrollview . ScrollToAsync ( 100 , 100 , true ) ;
105
114
break ;
106
115
}
107
116
} ;
108
117
109
118
btn1 . Clicked += async ( object sender , EventArgs e ) => {
110
- await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . Start , true ) ;
119
+ await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . Start , true ) ;
111
120
} ;
112
121
btn2 . Clicked += async ( object sender , EventArgs e ) => {
113
- await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . Center , true ) ;
122
+ await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . Center , true ) ;
114
123
} ;
115
124
btn3 . Clicked += async ( object sender , EventArgs e ) => {
116
- await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . End , true ) ;
125
+ await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . End , true ) ;
117
126
} ;
118
127
btn6 . Clicked += async ( object sender , EventArgs e ) => {
119
- await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . MakeVisible , true ) ;
128
+ await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . MakeVisible , true ) ;
120
129
} ;
121
130
btn7 . Clicked += ( object sender , EventArgs e ) =>
122
131
{
@@ -151,53 +160,58 @@ public ScrollGallery (ScrollOrientation orientation = ScrollOrientation.Vertical
151
160
_scrollview . HorizontalScrollBarVisibility = ScrollBarVisibility . Default ;
152
161
} ;
153
162
154
- _stack . Padding = new Size ( 20 , 60 ) ;
163
+ _stack . Padding = new Size ( 20 , 60 ) ;
155
164
156
- PopulateStack ( _stack ) ;
165
+ PopulateStack ( _stack ) ;
157
166
158
167
_scrollview . Orientation = _orientation ;
159
168
160
- if ( orientation == ScrollOrientation . Horizontal || orientation == ScrollOrientation . Both ) {
169
+ if ( orientation == ScrollOrientation . Horizontal || orientation == ScrollOrientation . Both )
170
+ {
161
171
_stack . Orientation = StackOrientation . Horizontal ;
162
172
}
163
173
164
- if ( orientation == ScrollOrientation . Both ) {
165
- var stack2 = new StackLayout ( ) ;
166
- PopulateStack ( stack2 ) ;
167
- _stack . Children . Add ( stack2 ) ;
174
+ if ( orientation == ScrollOrientation . Both )
175
+ {
176
+ var stack2 = new StackLayout ( ) ;
177
+ PopulateStack ( stack2 ) ;
178
+ _stack . Children . Add ( stack2 ) ;
168
179
}
169
180
170
181
Content = root ;
171
182
}
172
183
173
- void PopulateStack ( StackLayout stack )
184
+ void PopulateStack ( StackLayout stack )
174
185
{
175
- for ( int i = 0 ; i < 100 ; i ++ ) {
186
+ for ( int i = 0 ; i < 100 ; i ++ )
187
+ {
176
188
177
- var newButton = new Button { Text = "Foo Bar" , AutomationId = string . Format ( "btn_{0}" , i ) } ;
189
+ var newButton = new Button { Text = "Foo Bar" , AutomationId = string . Format ( "btn_{0}" , i ) } ;
178
190
if ( i == 49 )
179
191
newButton . Text = "the before" ;
180
192
181
- if ( i == 50 ) {
193
+ if ( i == 50 )
194
+ {
182
195
newButton . Text = "the scrollto button" ;
183
196
newButton . BackgroundColor = Color . Yellow ;
184
197
newButton . TextColor = Color . Black ;
185
198
_toNavigateTo = newButton ;
186
199
}
187
200
if ( i == 51 )
188
201
newButton . Text = "the after" ;
189
- if ( i == 53 ) {
202
+ if ( i == 53 )
203
+ {
190
204
newButton . Text = "the make visible from start" ;
191
205
newButton . Clicked += async ( object sender , EventArgs e ) => {
192
- await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . MakeVisible , true ) ;
206
+ await _scrollview . ScrollToAsync ( _toNavigateTo , ScrollToPosition . MakeVisible , true ) ;
193
207
} ;
194
208
}
195
209
196
- _buttons . Add ( newButton ) ;
197
- stack . Children . Add ( newButton ) ;
210
+ _buttons . Add ( newButton ) ;
211
+ stack . Children . Add ( newButton ) ;
198
212
}
199
213
200
- stack . Children . Add ( new Button { Text = "Foo Bottom" } ) ;
214
+ stack . Children . Add ( new Button { Text = "Foo Bottom" } ) ;
201
215
}
202
216
}
203
- }
217
+ }
0 commit comments