/// <summary> /// TabView is panned. Update horizontal line location during pan. /// </summary> private void OnPanChanged(object sender, PanChangedArgs args) { _previousPanChangedArgs = args; View leftChild = null; View rightChild = null; int leftIndex = (int)Math.Floor(args.Location); leftIndex = leftIndex < 0 ? _children.Count - 1 : leftIndex; int rightIndex = (int)Math.Ceiling(args.Location); rightIndex = rightIndex > _children.Count - 1 || leftIndex == _children.Count - 1 ? 0 : rightIndex; leftChild = _children[leftIndex].Child; rightChild = _children[rightIndex].Child; double panWidth = leftChild.Width + ((rightChild.Width - leftChild.Width) * (args.Location - leftIndex)); double panXDelta = ((rightChild.X + rightChild.TranslationX) - (leftChild.X + leftChild.TranslationX)) * (args.Location - leftIndex); double panX = leftChild.X + leftChild.TranslationX + panXDelta; ChildInfo lastChild = _children.Last(); ChildInfo firstChild = _children.First(); if ((panX + (panWidth / 2) > Width / 2 && lastChild.Size.Request.Width + lastChild.Child.TranslationX > Width) || (panX + (panWidth / 2) <= Width / 2 && firstChild.Child.TranslationX < 0)) { double newPanX = (Width - panWidth) / 2; double childrenPanDelta = panX - newPanX; View firstIndexChild = _children.First(c => c.Index == 0).Child; if (firstIndexChild.TranslationX - childrenPanDelta > 0) { childrenPanDelta += (firstIndexChild.TranslationX - childrenPanDelta); } View lastIndexChild = _children.First(c => c.Index == _children.Count - 1).Child; if (lastIndexChild.TranslationX + lastIndexChild.Bounds.Width - childrenPanDelta < Width) { childrenPanDelta = -(Width - (lastIndexChild.TranslationX + lastIndexChild.Bounds.Width)); } foreach (ChildInfo child in _children) { child.Child.TranslationX -= childrenPanDelta; } panX = newPanX; } LayoutChildIntoBoundingRegion(_focusLine, new Rectangle(panX, Height - FocusLineHeightRequest, panWidth, FocusLineHeightRequest)); }
private void OnTabViewPanChanged(object sender, PanChangedArgs args) { if (sender is CarouselView carouselView && carouselView.ItemsLayout is CarouselLayout carouselLayout) { if (_relatedViews == null) { _relatedViews = new RelatedViews(this); } foreach (View child in carouselLayout.Children) { ScrollView scrollView = VisualTreeHelper.FindVisualChildren <ScrollView>(child).FirstOrDefault(); if (scrollView != null && scrollView.ScrollY != _scrollY) { ScrollSource.UpdateScrollViewStart(this, _relatedViews.ContentPage, _relatedViews.NavigationPage, scrollView, _scrollY); } } } }
/// <summary> /// Event when CarouselLayout pan changed /// </summary> protected void OnPanChanged(object sender, PanChangedArgs args) { // Continue event raise PanChanged?.Invoke(this, args); }