@@ -33,15 +33,14 @@ public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle)
3333 VerticalOptions = LayoutOptions . FillAndExpand
3434 } ;
3535
36- var currentSessionsCarousel = CreateCurrentSessionsCarousel ( ) ;
36+ var pagesCarousel = CreatePagesCarousel ( ) ;
3737 var dots = CreatePagerIndicatorContainer ( ) ;
38- // _tabs = CreateTabsContainer();
3938 _tabs = CreateTabs ( ) ;
4039
41- switch ( currentSessionsCarousel . IndicatorStyle )
40+ switch ( pagesCarousel . IndicatorStyle )
4241 {
4342 case CarouselLayout . IndicatorStyleEnum . Dots :
44- relativeLayout . Children . Add ( currentSessionsCarousel ,
43+ relativeLayout . Children . Add ( pagesCarousel ,
4544 Constraint . RelativeToParent ( ( parent ) => { return parent . X ; } ) ,
4645 Constraint . RelativeToParent ( ( parent ) => { return parent . Y ; } ) ,
4746 Constraint . RelativeToParent ( ( parent ) => { return parent . Width ; } ) ,
@@ -50,7 +49,7 @@ public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle)
5049
5150 relativeLayout . Children . Add ( dots ,
5251 Constraint . Constant ( 0 ) ,
53- Constraint . RelativeToView ( currentSessionsCarousel ,
52+ Constraint . RelativeToView ( pagesCarousel ,
5453 ( parent , sibling ) => { return sibling . Height - 18 ; } ) ,
5554 Constraint . RelativeToParent ( parent => parent . Width ) ,
5655 Constraint . Constant ( 18 )
@@ -65,15 +64,15 @@ public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle)
6564 Constraint . Constant ( tabsHeight )
6665 ) ;
6766
68- relativeLayout . Children . Add ( currentSessionsCarousel ,
67+ relativeLayout . Children . Add ( pagesCarousel ,
6968 Constraint . RelativeToParent ( ( parent ) => { return parent . X ; } ) ,
7069 Constraint . RelativeToParent ( ( parent ) => { return parent . Y ; } ) ,
7170 Constraint . RelativeToParent ( ( parent ) => { return parent . Width ; } ) ,
7271 Constraint . RelativeToView ( _tabs , ( parent , sibling ) => { return parent . Height - ( sibling . Height ) ; } )
7372 ) ;
7473 break ;
7574 default :
76- relativeLayout . Children . Add ( currentSessionsCarousel ,
75+ relativeLayout . Children . Add ( pagesCarousel ,
7776 Constraint . RelativeToParent ( ( parent ) => { return parent . X ; } ) ,
7877 Constraint . RelativeToParent ( ( parent ) => { return parent . Y ; } ) ,
7978 Constraint . RelativeToParent ( ( parent ) => { return parent . Width ; } ) ,
@@ -85,16 +84,16 @@ public HomePage(CarouselLayout.IndicatorStyleEnum indicatorStyle)
8584 Content = relativeLayout ;
8685 }
8786
88- CarouselLayout CreateCurrentSessionsCarousel ( )
87+ CarouselLayout CreatePagesCarousel ( )
8988 {
9089 var carousel = new CarouselLayout {
9190 HorizontalOptions = LayoutOptions . FillAndExpand ,
9291 VerticalOptions = LayoutOptions . FillAndExpand ,
9392 IndicatorStyle = _indicatorStyle ,
9493 ItemTemplate = new DataTemplate ( typeof ( HomeView ) )
9594 } ;
96- carousel . SetBinding ( CarouselLayout . ItemsSourceProperty , "CurrentSessions " ) ;
97- carousel . SetBinding ( CarouselLayout . SelectedItemProperty , "CurrentSession " , BindingMode . TwoWay ) ;
95+ carousel . SetBinding ( CarouselLayout . ItemsSourceProperty , "Pages " ) ;
96+ carousel . SetBinding ( CarouselLayout . SelectedItemProperty , "CurrentPage " , BindingMode . TwoWay ) ;
9897
9998 return carousel ;
10099 }
@@ -109,8 +108,8 @@ View CreatePagerIndicatorContainer()
109108 View CreatePagerIndicators ( )
110109 {
111110 var pagerIndicator = new PagerIndicatorDots ( ) { DotSize = 5 , DotColor = Color . Black } ;
112- pagerIndicator . SetBinding ( PagerIndicatorDots . ItemsSourceProperty , "CurrentSessions " ) ;
113- pagerIndicator . SetBinding ( PagerIndicatorDots . SelectedItemProperty , "CurrentSession " ) ;
111+ pagerIndicator . SetBinding ( PagerIndicatorDots . ItemsSourceProperty , "Pages " ) ;
112+ pagerIndicator . SetBinding ( PagerIndicatorDots . SelectedItemProperty , "CurrentPage " ) ;
114113 return pagerIndicator ;
115114 }
116115
@@ -125,55 +124,11 @@ View CreateTabs()
125124 {
126125 var pagerIndicator = new PagerIndicatorTabs ( ) { HorizontalOptions = LayoutOptions . CenterAndExpand } ;
127126 pagerIndicator . RowDefinitions . Add ( new RowDefinition ( ) { Height = 50 } ) ;
128- pagerIndicator . SetBinding ( PagerIndicatorTabs . ColumnDefinitionsProperty , "CurrentSessions" , BindingMode . Default , new SpacingConverter ( ) ) ;
129- pagerIndicator . SetBinding ( PagerIndicatorTabs . ItemsSourceProperty , "CurrentSessions" ) ;
130- pagerIndicator . SetBinding ( PagerIndicatorTabs . SelectedItemProperty , "CurrentSession" ) ;
131-
132- // grid.Children.Add(new StackLayout {
133- // Orientation = StackOrientation.Vertical,
134- // HorizontalOptions = LayoutOptions.Center,
135- // Padding = new Thickness(5),
136- // Children = {
137- // new Image { Source = "icon.png", HeightRequest = 20 },
138- // new Label { Text = "Tab One", FontSize = 11 }
139- // }
140- // }, 0, 0);
141- // grid.Children.Add(new StackLayout {
142- // Orientation = StackOrientation.Vertical,
143- // HorizontalOptions = LayoutOptions.Center,
144- // Padding = new Thickness(5),
145- // Children = {
146- // new Image { Source = "icon.png", HeightRequest = 20 },
147- // new Label { Text = "Tab Two", FontSize = 11 }
148- // }
149- // }, 1, 0);
150- // grid.Children.Add(new StackLayout {
151- // Orientation = StackOrientation.Vertical,
152- // HorizontalOptions = LayoutOptions.Center,
153- // Padding = new Thickness(5),
154- // Children = {
155- // new Image { Source = "icon.png", HeightRequest = 20 },
156- // new Label { Text = "Tab Three", FontSize = 11 }
157- // }
158- // }, 2, 0);
159- // grid.Children.Add(new StackLayout {
160- // Orientation = StackOrientation.Vertical,
161- // HorizontalOptions = LayoutOptions.Center,
162- // Padding = new Thickness(5),
163- // Children = {
164- // new Image { Source = "icon.png", HeightRequest = 20 },
165- // new Label { Text = "Tab Four", FontSize = 11 }
166- // }
167- // }, 3, 0);
127+ pagerIndicator . SetBinding ( PagerIndicatorTabs . ColumnDefinitionsProperty , "Pages" , BindingMode . Default , new SpacingConverter ( ) ) ;
128+ pagerIndicator . SetBinding ( PagerIndicatorTabs . ItemsSourceProperty , "Pages" ) ;
129+ pagerIndicator . SetBinding ( PagerIndicatorTabs . SelectedItemProperty , "CurrentPage" ) ;
168130
169131 return pagerIndicator ;
170-
171- // var pagerIndicator = new PagerIndicatorDots() { DotSize = 10, DotColor = Color.White, Spacing = 0, HorizontalOptions = LayoutOptions.FillAndExpand };
172- //
173- // pagerIndicator.SetBinding (PagerIndicatorDots.ItemsSourceProperty, "CurrentSessions");
174- // pagerIndicator.SetBinding (PagerIndicatorDots.SelectedItemProperty, "CurrentSession");
175- //
176- // return pagerIndicator;
177132 }
178133 }
179134
@@ -196,109 +151,5 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
196151 throw new NotImplementedException ( ) ;
197152 }
198153 }
199-
200- public class PipSet : StackLayout
201- {
202- int _selectedIndex ;
203-
204- public PipSet ( )
205- {
206- Orientation = StackOrientation . Horizontal ;
207- HorizontalOptions = LayoutOptions . Center ;
208- Spacing = 4 ;
209- }
210-
211- public static BindableProperty ItemsSourceProperty =
212- BindableProperty . Create < PipSet , IList > (
213- pips => pips . ItemsSource ,
214- null ,
215- BindingMode . OneWay ,
216- propertyChanging : ( bindable , oldValue , newValue ) => {
217- ( ( PipSet ) bindable ) . ItemsSourceChanging ( ) ;
218- } ,
219- propertyChanged : ( bindable , oldValue , newValue ) => {
220- ( ( PipSet ) bindable ) . ItemsSourceChanged ( ) ;
221- }
222- ) ;
223-
224- public IList ItemsSource {
225- get {
226- return ( IList ) GetValue ( ItemsSourceProperty ) ;
227- }
228- set {
229- SetValue ( ItemsSourceProperty , value ) ;
230- }
231- }
232-
233- public static BindableProperty SelectedItemProperty =
234- BindableProperty . Create < PipSet , object > (
235- pips => pips . SelectedItem ,
236- null ,
237- BindingMode . TwoWay ,
238- propertyChanged : ( bindable , oldValue , newValue ) => {
239- ( ( PipSet ) bindable ) . SelectedItemChanged ( ) ;
240- } ) ;
241-
242- public object SelectedItem {
243- get {
244- return GetValue ( SelectedItemProperty ) ;
245- }
246- set {
247- SetValue ( SelectedItemProperty , value ) ;
248- }
249- }
250-
251- void ItemsSourceChanging ( )
252- {
253- if ( ItemsSource != null )
254- _selectedIndex = ItemsSource . IndexOf ( SelectedItem ) ;
255- }
256-
257- void ItemsSourceChanged ( )
258- {
259- if ( ItemsSource == null ) return ;
260-
261- var countDelta = ItemsSource . Count - Children . Count ;
262-
263- if ( countDelta > 0 ) {
264- for ( var i = 0 ; i < countDelta ; i ++ ) {
265- Children . Add ( CreatePip ( ) ) ;
266- }
267- } else if ( countDelta < 0 ) {
268- for ( var i = 0 ; i < - countDelta ; i ++ ) {
269- Children . RemoveAt ( 0 ) ;
270- }
271- }
272-
273- // if (_selectedIndex >= 0 && _selectedIndex < ItemsSource.Count)
274- // SelectedItem = ItemsSource [_selectedIndex];
275-
276- // UpdateSelection ();
277- }
278-
279- void SelectedItemChanged ( ) {
280- var selectedIndex = ItemsSource . IndexOf ( SelectedItem ) ;
281- var pips = Children . Cast < Image > ( ) . ToList ( ) ;
282-
283- foreach ( var pip in pips ) UnselectPip ( pip ) ;
284-
285- if ( selectedIndex > - 1 ) SelectPip ( pips [ selectedIndex ] ) ;
286- }
287-
288- static View CreatePip ( )
289- {
290- return new Image { Source = "pip.png" } ;
291- }
292-
293- static void UnselectPip ( Image pip )
294- {
295- pip . Source = "pip.png" ;
296- }
297-
298- static void SelectPip ( Image pip )
299- {
300- pip . Source = "pip_selected.png" ;
301- }
302- }
303154}
304155
0 commit comments