public SpacingItemDecoration(StaggeredGridItemsLayout itemsLayout) { if (itemsLayout == null) { throw new ArgumentNullException(nameof(itemsLayout)); } switch (itemsLayout) { case StaggeredGridItemsLayout gridItemsLayout: _orientation = gridItemsLayout.Orientation; _horizontalSpacing = gridItemsLayout.HorizontalItemSpacing; _verticalSpacing = gridItemsLayout.VerticalItemSpacing; _span = gridItemsLayout.Span; break; } }
public override void Draw(CGRect rect) { base.Draw(rect); GradientColorStackLayout stack = this.Element as GradientColorStackLayout; CGColor startColor = stack.StartColor.ToCGColor(); CGColor centerColor = stack.CenterColor.ToCGColor(); CGColor endColor = stack.EndColor.ToCGColor(); float yCenter = stack.YCenter; ItemsLayoutOrientation direction = stack.Direction; bool hasCenterColor = stack.HasCenterColor; CAGradientLayer gradientLayer = null; if (direction == ItemsLayoutOrientation.Vertical) { gradientLayer = new CAGradientLayer(); } if (direction == ItemsLayoutOrientation.Horizontal) { gradientLayer = new CAGradientLayer() { StartPoint = new CGPoint(0, 0.5), EndPoint = new CGPoint(1, 0.5) }; } gradientLayer.Frame = rect; if (hasCenterColor) { gradientLayer.Locations = new NSNumber[] { new NSNumber(0.5F), new NSNumber(yCenter), new NSNumber(1F) }; gradientLayer.Colors = new CGColor[] { startColor, centerColor, endColor }; } else { gradientLayer.Locations = new NSNumber[] { new NSNumber(yCenter), new NSNumber(1F) }; gradientLayer.Colors = new CGColor[] { startColor, endColor }; } NativeView.Layer.InsertSublayer(gradientLayer, 0); }
public ObservableCodeCollectionViewGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical, bool grid = true, int initialItems = 1000, bool addItemsWithTimer = false) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; IItemsLayout itemsLayout = grid ? new GridItemsLayout(3, orientation) : new ListItemsLayout(orientation) as IItemsLayout; var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" };
public TemplateCodeCollectionViewGridGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemsLayout = new GridItemsLayout(2, orientation); var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, 100); var spanSetter = new SpanSetter(collectionView); layout.Children.Add(generator); layout.Children.Add(spanSetter); Grid.SetRow(spanSetter, 1); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 2); Content = layout; spanSetter.UpdateSpan(); generator.GenerateItems(); }
ListViewBase CreateCarouselListLayout(ItemsLayoutOrientation layoutOrientation) { Windows.UI.Xaml.Controls.ListView listView; if (layoutOrientation == ItemsLayoutOrientation.Horizontal) { listView = new FormsListView() { Style = (Windows.UI.Xaml.Style)UWPApp.Current.Resources["HorizontalCarouselListStyle"], ItemsPanel = (ItemsPanelTemplate)UWPApp.Current.Resources["HorizontalListItemsPanel"] }; } else { listView = new FormsListView() { Style = (Windows.UI.Xaml.Style)UWPApp.Current.Resources["VerticalCarouselListStyle"] }; } return(listView); }
ListViewBase CreateCarouselListLayout(ItemsLayoutOrientation layoutOrientation) { Windows.UI.Xaml.Controls.ListView listView; if (layoutOrientation == ItemsLayoutOrientation.Horizontal) { listView = new FormsListView() { Style = (Windows.UI.Xaml.Style)UWPApp.Current.Resources["HorizontalCarouselListStyle"], ItemsPanel = (ItemsPanelTemplate)UWPApp.Current.Resources["HorizontalListItemsPanel"] }; } else { listView = new FormsListView() { Style = (Windows.UI.Xaml.Style)UWPApp.Current.Resources["VerticalCarouselListStyle"] }; } listView.Padding = new Windows.UI.Xaml.Thickness(Carousel.PeekAreaInsets.Left, Carousel.PeekAreaInsets.Top, Carousel.PeekAreaInsets.Right, Carousel.PeekAreaInsets.Bottom); return(listView); }
public CarouselCodeGallery(ItemsLayoutOrientation orientation) { On <iOS>().SetLargeTitleDisplay(LargeTitleDisplayMode.Never); _scrollInfoLabel.MaxLines = 1; _scrollInfoLabel.LineBreakMode = LineBreakMode.TailTruncation; _orientation = orientation; Title = $"CarouselView (Code, {orientation})"; var nItems = 5; var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemsLayout = new LinearItemsLayout(orientation) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = ExampleTemplates.CarouselTemplate(); var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, Position = 2, Margin = new Thickness(0, 10, 0, 10), BackgroundColor = Color.LightGray, AutomationId = "TheCarouselView" }; if (orientation == ItemsLayoutOrientation.Horizontal) { carouselView.PeekAreaInsets = new Thickness(30, 0, 30, 0); } else { carouselView.PeekAreaInsets = new Thickness(0, 30, 0, 30); } carouselView.Scrolled += CarouselView_Scrolled; StackLayout stacklayoutInfo = GetReadOnlyInfo(carouselView); var generator = new ItemsSourceGenerator(carouselView, initialItems: nItems, itemsSourceType: ItemsSourceType.ObservableCollection); layout.Children.Add(generator); var positionControl = new PositionControl(carouselView, nItems); layout.Children.Add(positionControl); var spacingModifier = new SpacingModifier(carouselView.ItemsLayout, "Update Spacing"); layout.Children.Add(spacingModifier); layout.Children.Add(stacklayoutInfo); var stckPeek = new StackLayout { Orientation = StackOrientation.Horizontal }; stckPeek.Children.Add(new Label { Text = "Peek" }); var padi = new Slider { Maximum = 100, Minimum = 0, Value = 30, WidthRequest = 100, BackgroundColor = Color.Pink }; padi.ValueChanged += (s, e) => { var peek = padi.Value; if (orientation == ItemsLayoutOrientation.Horizontal) { carouselView.PeekAreaInsets = new Thickness(peek, 0, peek, 0); } else { carouselView.PeekAreaInsets = new Thickness(0, peek, 0, peek); } }; stckPeek.Children.Add(padi); stacklayoutInfo.Children.Add(stckPeek); stacklayoutInfo.Children.Add(_scrollInfoLabel); var content = new Grid(); content.Children.Add(carouselView); #if DEBUG // Uncomment this line to add a helper to visualize the center of each element. //content.Children.Add(CreateDebuggerLines()); #endif layout.Children.Add(content); Grid.SetRow(positionControl, 1); Grid.SetRow(stacklayoutInfo, 2); Grid.SetRow(spacingModifier, 3); Grid.SetRow(content, 4); Content = layout; generator.CollectionChanged += (sender, e) => { positionControl.UpdatePositionCount(generator.Count); }; generator.GenerateItems(); }
public static bool IsListViewItemVisible(FrameworkElement element, FrameworkElement container, ItemsLayoutOrientation itemsLayoutOrientation) { if (element == null || container == null) { return(false); } if (element.Visibility != Visibility.Visible) { return(false); } var elementBounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight)); var containerBounds = new Rect(0, 0, container.ActualWidth, container.ActualHeight); switch (itemsLayoutOrientation) { case ItemsLayoutOrientation.Vertical: return(elementBounds.Top < containerBounds.Bottom && elementBounds.Bottom > containerBounds.Top); default: return(elementBounds.Left < containerBounds.Right && elementBounds.Right > containerBounds.Left); } ; }
public static (int firstVisibleItemIndex, int lastVisibleItemIndex, int centerItemIndex) GetVisibleIndexes(this ListViewBase listViewBase, ItemsLayoutOrientation itemsLayoutOrientation, bool goingNext) { int firstVisibleItemIndex = -1; int lastVisibleItemIndex = -1; var itemsPanel = (listViewBase.ItemsPanelRoot as ItemsStackPanel); if (itemsPanel != null) { firstVisibleItemIndex = itemsPanel.FirstVisibleIndex; lastVisibleItemIndex = itemsPanel.LastVisibleIndex; } else { var scrollViewer = listViewBase.GetFirstDescendant <ScrollViewer>(); var presenters = listViewBase.GetChildren <ListViewItemPresenter>(); if (presenters != null || scrollViewer == null) { int count = 0; foreach (ListViewItemPresenter presenter in presenters) { if (IsListViewItemVisible(presenter, scrollViewer, itemsLayoutOrientation)) { if (firstVisibleItemIndex == -1) { firstVisibleItemIndex = count; } lastVisibleItemIndex = count; } count++; } } } double center = (lastVisibleItemIndex + firstVisibleItemIndex) / 2.0; int centerItemIndex = goingNext ? (int)Math.Ceiling(center) : (int)Math.Floor(center); return(firstVisibleItemIndex, lastVisibleItemIndex, centerItemIndex); }
public ListItemsLayout(ItemsLayoutOrientation orientation) : base(orientation) { }
public ObservableCodeCollectionViewGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical, bool grid = true) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; IItemsLayout itemsLayout = grid ? new GridItemsLayout(3, orientation) : new ListItemsLayout(orientation) as IItemsLayout; var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate }; var generator = new ItemsSourceGenerator(collectionView); var remover = new ItemRemover(collectionView); var adder = new ItemAdder(collectionView); var replacer = new ItemReplacer(collectionView); var mover = new ItemMover(collectionView); layout.Children.Add(generator); layout.Children.Add(remover); Grid.SetRow(remover, 1); layout.Children.Add(adder); Grid.SetRow(adder, 2); layout.Children.Add(replacer); Grid.SetRow(replacer, 3); layout.Children.Add(mover); Grid.SetRow(mover, 4); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 5); Content = layout; generator.GenerateObservableCollection(); }
public ObservableCodeCollectionViewGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical, bool grid = true, int initialItems = 1000, bool addItemsWithTimer = false, ItemsUpdatingScrollMode scrollMode = ItemsUpdatingScrollMode.KeepItemsInView) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; IItemsLayout itemsLayout = grid ? new GridItemsLayout(3, orientation) : new LinearItemsLayout(orientation) as IItemsLayout; var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview", Header = "This is the header", ItemsUpdatingScrollMode = scrollMode }; var generator = new ItemsSourceGenerator(collectionView, initialItems, ItemsSourceType.ObservableCollection); var remover = new ItemRemover(collectionView); var adder = new ItemAdder(collectionView); var replacer = new ItemReplacer(collectionView); var mover = new ItemMover(collectionView); var inserter = new ItemInserter(collectionView); layout.Children.Add(generator); layout.Children.Add(remover); Grid.SetRow(remover, 1); layout.Children.Add(adder); Grid.SetRow(adder, 2); layout.Children.Add(replacer); Grid.SetRow(replacer, 3); layout.Children.Add(mover); Grid.SetRow(mover, 4); layout.Children.Add(inserter); Grid.SetRow(inserter, 5); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 6); Content = layout; if (addItemsWithTimer) { generator.GenerateEmptyObservableCollectionAndAddItemsEverySecond(); } else { generator.GenerateItems(); } }
public static (int firstVisibleItemIndex, int lastVisibleItemIndex, int centerItemIndex) GetVisibleIndexes(ListViewBase listViewBase, ItemsLayoutOrientation itemsLayoutOrientation) { int firstVisibleItemIndex = -1; int lastVisibleItemIndex = -1; int centerItemIndex = -1; var scrollViewer = listViewBase.GetFirstDescendant <ScrollViewer>(); var presenters = listViewBase.GetChildren <ListViewItemPresenter>(); if (presenters != null || scrollViewer == null) { int count = 0; foreach (ListViewItemPresenter presenter in presenters) { if (CollectionViewExtensions.IsListViewItemVisible(presenter, scrollViewer, itemsLayoutOrientation)) { if (firstVisibleItemIndex == -1) { firstVisibleItemIndex = count; } lastVisibleItemIndex = count; } count++; } centerItemIndex = (lastVisibleItemIndex + firstVisibleItemIndex) / 2; } return(firstVisibleItemIndex, lastVisibleItemIndex, centerItemIndex); }
protected ItemsLayout(ItemsLayoutOrientation orientation) { CollectionView.VerifyCollectionViewFlagEnabled(constructorHint: nameof(ItemsLayout)); Orientation = orientation; }
public CustomLinearItemsLayout([CustomParameter("Orientation")] ItemsLayoutOrientation orientation) : base(orientation) { }
protected virtual ItemsViewScrolledEventArgs ComputeVisibleIndexes(ItemsViewScrolledEventArgs args, ItemsLayoutOrientation orientation, bool advancing) { var(firstVisibleItemIndex, lastVisibleItemIndex, centerItemIndex) = GetVisibleIndexes(orientation, advancing); args.FirstVisibleItemIndex = firstVisibleItemIndex; args.CenterItemIndex = centerItemIndex; args.LastVisibleItemIndex = lastVisibleItemIndex; return(args); }
public SwipeItemsLayout(ItemsLayoutOrientation orientation) : base(orientation) { }
public ObservableMultiItemCollectionViewGallery(ItemsLayoutOrientation orientation = ItemsLayoutOrientation.Vertical, bool grid = true, int initialItems = 1000, bool withIndex = false) { var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var itemsLayout = grid ? new GridItemsLayout(3, orientation) : new ListItemsLayout(orientation) as IItemsLayout; var itemTemplate = ExampleTemplates.PhotoTemplate(); var collectionView = new CollectionView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, AutomationId = "collectionview" }; var generator = new ItemsSourceGenerator(collectionView, initialItems, ItemsSourceType.MultiTestObservableCollection); var remover = new MultiItemRemover(collectionView, withIndex); var adder = new MultiItemAdder(collectionView, withIndex); var replacer = new MultiItemReplacer(collectionView); var mover = new MultiItemMover(collectionView); layout.Children.Add(generator); layout.Children.Add(remover); Grid.SetRow(remover, 1); layout.Children.Add(adder); Grid.SetRow(adder, 2); layout.Children.Add(replacer); Grid.SetRow(replacer, 3); layout.Children.Add(mover); Grid.SetRow(mover, 4); layout.Children.Add(collectionView); Grid.SetRow(collectionView, 5); Content = layout; generator.GenerateItems(); }
protected ItemsLayout([Parameter("Orientation")] ItemsLayoutOrientation orientation) { Orientation = orientation; }
public StaggeredGridItemsLayout([Parameter("Orientation")] ItemsLayoutOrientation orientation) : base(orientation) { }
protected override ItemsViewScrolledEventArgs ComputeVisibleIndexes(ItemsViewScrolledEventArgs args, ItemsLayoutOrientation orientation, bool advancing) { args = base.ComputeVisibleIndexes(args, orientation, advancing); if (Element.Loop) { args.FirstVisibleItemIndex %= ItemCount; args.CenterItemIndex %= ItemCount; args.LastVisibleItemIndex %= ItemCount; } return(args); }
public StaggeredGridItemsLayout(int span, [Parameter("Orientation")] ItemsLayoutOrientation orientation) : base(span, orientation) { }
public LinearItemsLayout([Parameter("Orientation")] ItemsLayoutOrientation orientation) : base(orientation) { }
public static TCollectionView GridStyle <TCollectionView>(this TCollectionView collection, ItemsLayoutOrientation orientation, int span, int spacing) where TCollectionView : CollectionView { collection.ItemsLayout = new GridItemsLayout(orientation) { Span = span, VerticalItemSpacing = spacing, HorizontalItemSpacing = spacing, }; return(collection); }