public ScrollToCodeGallery(IItemsLayout itemsLayout, ScrollToMode mode = ScrollToMode.Position, Func <DataTemplate> dataTemplate = null, Func <CollectionView> createCollectionView = null) { createCollectionView = createCollectionView ?? (() => new CollectionView()); Title = $"ScrollTo (Code, {itemsLayout})"; var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemTemplate = dataTemplate == null?ExampleTemplates.ScrollToIndexTemplate() : dataTemplate(); var collectionView = createCollectionView(); collectionView.ItemsLayout = itemsLayout; collectionView.ItemTemplate = itemTemplate; var generator = new ItemsSourceGenerator(collectionView, initialItems: 50); layout.Children.Add(generator); if (mode == ScrollToMode.Position) { var scrollToControl = new ScrollToIndexControl(collectionView); layout.Children.Add(scrollToControl); Grid.SetRow(scrollToControl, 1); } else { var scrollToControl = new ScrollToItemControl(collectionView); layout.Children.Add(scrollToControl); Grid.SetRow(scrollToControl, 1); } layout.Children.Add(collectionView); Grid.SetRow(collectionView, 2); Content = layout; generator.GenerateItems(); }
async void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) { ClearRtlScrollCheck(); // Adding items into the view while scrolling to the end can cause it to fail, as // the items have not actually been laid out and return incorrect scroll position // values. The ScrollViewRenderer for Android does something similar by waiting up // to 10ms for layout to occur. int cycle = 0; while (Element != null && !Element.IsInNativeLayout) { await Task.Delay(TimeSpan.FromMilliseconds(1)); cycle++; if (cycle >= 10) { break; } } if (Element == null) { return; } double x = e.ScrollX, y = e.ScrollY; ScrollToMode mode = e.Mode; if (mode == ScrollToMode.Element) { Point pos = Element.GetScrollPositionForElement((VisualElement)e.Element, e.Position); x = pos.X; y = pos.Y; mode = ScrollToMode.Position; } if (mode == ScrollToMode.Position) { Control.ChangeView(x, y, null, !e.ShouldAnimate); } Element.SendScrollFinished(); }
void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) { double x = e.ScrollX, y = e.ScrollY; ScrollToMode mode = e.Mode; if (mode == ScrollToMode.Element) { Point pos = Controller.GetScrollPositionForElement((VisualElement)e.Element, e.Position); x = pos.X; y = pos.Y; mode = ScrollToMode.Position; } if (mode == ScrollToMode.Position) { Control.ChangeView(x, y, null, !e.ShouldAnimate); } }
/// <summary> /// Selects the specified row /// </summary> /// <param name="Index">row Index</param> /// <param name="Animated">If set to <c>true</c> animated, default(true)</param> /// <param name="Mode">Scroll Mode, default(None)</param> /// <param name="AdditonalOffset">Additonal offset(default(0)</param> public void SelectRow(int Index, bool Animated = true, ScrollToMode Mode = ScrollToMode.None, float AdditonalOffset = 0) { Processor.UpdateSelection(Index); nfloat top = -1; switch (Mode) { case ScrollToMode.None: { top = this.ContentOffset.Y; } break; case ScrollToMode.Top: { top = Processor.TopYForRow(Index); } break; case ScrollToMode.Middle: { top = Processor.TopYForRow(Index); var bottomOffset = (this.Frame.Height - Processor.RowHeight) + this.Theme.HeaderHeight; bottomOffset = (((bottomOffset - this.Frame.Top) - 20) - AdditonalOffset); top -= ((bottomOffset / 2) - (Processor.RowHeight / 2)); } break; case ScrollToMode.Bottom: { top = Processor.TopYForRow(Index); var bottomOffset = (this.Frame.Height - Processor.RowHeight) + this.Theme.HeaderHeight; top -= (((bottomOffset - this.Frame.Top) - 20) - AdditonalOffset); } break; } this.ContentOffset = new CGPoint(0, top); }
private void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) { double x = e.ScrollX, y = e.ScrollY; ScrollToMode mode = e.Mode; if (mode == ScrollToMode.Element) { Point pos = Controller.GetScrollPositionForElement((VisualElement)e.Element, e.Position); x = pos.X; y = pos.Y; mode = ScrollToMode.Position; } if (mode == ScrollToMode.Position) { Control.Hadjustment.Value = x; Control.Vadjustment.Value = y; } Controller.SendScrollFinished(); }