/// <summary>
		/// Initializes a new instance of the <see cref="ExtendedScrollViewPage"/> class.
		/// </summary>
		public ExtendedScrollViewPage()
		{
			InitializeComponent();

			var container = new StackLayout()
			{
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand
			};

			var buttonToScroll = new Button() { Text = "Scroll to end" };

			container.Children.Add(buttonToScroll);

			for (var i = 0; i < 10; i++)
			{
				container.Children.Add(new Image
				{
					Aspect = Aspect.AspectFill,
					Source = ImageSource.FromUri(new Uri("http://www.stockvault.net/data/2011/05/31/124348/small.jpg")),
					HeightRequest = IMAGE_HEIGHT

				});
			}
			var sv = new ExtendedScrollView
			{
				Content = container,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand
			};

			sv.Scrolled += async (arg1, arg2) =>
			{
				if (!(arg2.Y > sv.Bounds.Height) || _displayAlert)
				{
					return;
				}

				_displayAlert = true;
				await DisplayAlert("Scroll event", "User scrolled pass bounds", "Ok", "cancel");
			};

			buttonToScroll.Clicked += (sender, e) =>
			{
				sv.Position = new Point(sv.Position.X, sv.ContentSize.Height - IMAGE_HEIGHT);
			};

			Content = sv;
		}
Exemple #2
0
        /// <summary>
        /// Handles the <see cref="E:ElementChanged" /> event.
        /// </summary>
        /// <param name="e">The <see cref="VisualElementChangedEventArgs"/> instance containing the event data.</param>
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            Scrolled += (sender, ev) => {
                ExtendedScrollView sv = (ExtendedScrollView)Element;
                sv.UpdateBounds(Bounds.ToRectangle());
            };

            if (e.OldElement != null)
            {
                e.OldElement.PropertyChanged -= OnElementPropertyChanged;
            }
            e.NewElement.PropertyChanged += OnElementPropertyChanged;
        }
Exemple #3
0
        /// <summary>
        /// Handles the <see cref="E:ElementPropertyChanged" /> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="PropertyChangedEventArgs"/> instance containing the event data.</param>
        protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == ExtendedScrollView.PositionProperty.PropertyName)
            {
                ExtendedScrollView sv = (ExtendedScrollView)Element;
                Point pt = sv.Position;

                if (System.Math.Abs(Bounds.Location.Y - pt.Y) < _epsilon &&
                    System.Math.Abs(Bounds.Location.X - pt.X) < _epsilon)
                {
                    return;
                }

                ScrollRectToVisible(
                    new CGRect((float)pt.X, (float)pt.Y, Bounds.Width, Bounds.Height), sv.AnimateScroll);
            }
        }