protected override void OnElementChanged (ElementChangedEventArgs<View> e)
		{
			base.OnElementChanged (e);
			//If the NewElement has been queued up
			if (e.NewElement != null) {
				//Set SliderView Instance
				_sliderView = e.NewElement as SliderView;
				//Make the currentView the same dimensions of the SliderView
				_sliderView.Children [currentViewIndex].HeightRequest = _sliderView.Height;
				_sliderView.Children [currentViewIndex].WidthRequest = _sliderView.Width;
				//This is an optional thing, really depends on how you want to use this SliderView
				_sliderView.Children [currentViewIndex].BackgroundColor = _sliderView.BackgroundColor;
			}

			//Create the gesture that brings the view in from the right side
			rightGesture = new UISwipeGestureRecognizer (swipe => {
				Console.WriteLine("Swipe Left");
				//Check to make sure we aren't on the current view
				if (_sliderView.Children.Count > currentViewIndex + 1 ) {
					//Add one to the index
					currentViewIndex++;

					_sliderView.CurrentView = _sliderView.Children [currentViewIndex];
					_sliderView.CurrentView.HeightRequest = _sliderView.Height;
					_sliderView.CurrentView.WidthRequest = _sliderView.Width;
					_sliderView.CurrentView.BackgroundColor = _sliderView.BackgroundColor;

					//Translate the CurrentView onto the ViewScreen
					TranslateToCurrentView ("Left");
				}
			}) {
				Direction = UISwipeGestureRecognizerDirection.Left
			};

			//Create the gesture that brings the view in from the left side
			leftGesture = new UISwipeGestureRecognizer (swipe => {
				//Check to make sure we aren't at the first view
				if (currentViewIndex != 0) {
					//Drop the index one
					currentViewIndex--;

					//Set the new CurrentView
					_sliderView.CurrentView = _sliderView.Children [currentViewIndex];
					//Set the size of the CurrentView to the size of the SliderView
					_sliderView.CurrentView.HeightRequest = _sliderView.Height;
					_sliderView.CurrentView.WidthRequest = _sliderView.Width;
					//This is an optional thing, really depends on how you want to use this SliderView
					_sliderView.CurrentView.BackgroundColor = _sliderView.BackgroundColor;

					//Translate the CurrentView onto the ViewScreen
					TranslateToCurrentView ("Right");
				}
			}) {
				Direction = UISwipeGestureRecognizerDirection.Right
			};

			//Add the Gesture Recognizers to the SliderView
			AddGestureRecognizer (rightGesture);
			AddGestureRecognizer (leftGesture);
		}
		public SliderViewPage ()
		{
			//Create the views for the Slider
			Image image1 = new Image {
				Source = FileImageSource.FromFile("image1.png"),
			};
			Image image2 = new Image {
				Source = FileImageSource.FromFile("image2.png"),
			};
			Image image3 = new Image {
				Source = FileImageSource.FromFile("image3.png"),
			};
			Image image4 = new Image {
				Source = FileImageSource.FromFile("image4.png"),
			};
			RandomAbsoluteLayout randomView = new RandomAbsoluteLayout ();

			//Create the Slider by passing in the first view and the sizes
			SliderView slider = new SliderView (image1, App.ScreenHeight * 0.5, App.ScreenWidth) {
				BackgroundColor = Color.Gray,
				TransitionLength = 200,
				StyleId = "SliderView",
				MinimumSwipeDistance = 50
			};

			//Create a button to add items to the Slider
			Button addChildrenButton = new Button { Text = "Add View" };
			addChildrenButton.Clicked += (object sender, EventArgs e) => {
				slider.Children.Add(new StackLayout{
					HorizontalOptions = LayoutOptions.CenterAndExpand,
					VerticalOptions = LayoutOptions.CenterAndExpand,
					BackgroundColor = Color.Green,
					Children = {
						new Label {Text = "YAY"}
					}
				});
			};

			//Create a button to remove items from the slider
			Button removeChildrenButton = new Button { Text = "Remove View" };
			removeChildrenButton.Clicked += (object sender, EventArgs e) => {
				slider.Children.RemoveAt(slider.Children.Count-1);
			};

			//Add the views to the slider
			slider.Children.Add (image2);
			slider.Children.Add (randomView);
			slider.Children.Add (image3);
			slider.Children.Add (image4);

			//Set the content of the page
			Content = new StackLayout {
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.Start,
				Children = { 
					slider,
					addChildrenButton,
					removeChildrenButton
				}
			};
		}
Exemple #3
0
        public SliderViewPage()
        {
            //Create the views for the Slider
            Image image1 = new Image {
                Source = FileImageSource.FromFile("image1.png"),
            };
            Image image2 = new Image {
                Source = FileImageSource.FromFile("image2.png"),
            };
            Image image3 = new Image {
                Source = FileImageSource.FromFile("image3.png"),
            };
            Image image4 = new Image {
                Source = FileImageSource.FromFile("image4.png"),
            };
            RandomAbsoluteLayout randomView = new RandomAbsoluteLayout();

            //Create the Slider by passing in the first view and the sizes
            SliderView slider = new SliderView(image1, App.ScreenHeight * 0.5, App.ScreenWidth)
            {
                BackgroundColor      = Color.Gray,
                TransitionLength     = 200,
                StyleId              = "SliderView",
                MinimumSwipeDistance = 50
            };

            //Create a button to add items to the Slider
            Button addChildrenButton = new Button {
                Text = "Add View"
            };

            addChildrenButton.Clicked += (object sender, EventArgs e) => {
                slider.Children.Add(new StackLayout {
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    BackgroundColor   = Color.Green,
                    Children          =
                    {
                        new Label {
                            Text = "YAY"
                        }
                    }
                });
            };

            //Create a button to remove items from the slider
            Button removeChildrenButton = new Button {
                Text = "Remove View"
            };

            removeChildrenButton.Clicked += (object sender, EventArgs e) => {
                slider.Children.RemoveAt(slider.Children.Count - 1);
            };

            //Add the views to the slider
            slider.Children.Add(image2);
            slider.Children.Add(randomView);
            slider.Children.Add(image3);
            slider.Children.Add(image4);

            //Set the content of the page
            Content = new StackLayout {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Start,
                Children          =
                {
                    slider,
                    addChildrenButton,
                    removeChildrenButton
                }
            };
        }