示例#1
0
        public CarouselCodeGallery(ItemsLayoutOrientation orientation)
        {
            Title = $"CarouselView (Code, {orientation})";

            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 ListItemsLayout(orientation)
            {
                SnapPointsType      = SnapPointsType.MandatorySingle,
                SnapPointsAlignment = SnapPointsAlignment.Center
            };

            var itemTemplate = ExampleTemplates.CarouselTemplate();

            var carouselView = new CarouselView
            {
                ItemsLayout  = itemsLayout,
                ItemTemplate = itemTemplate,
            };

            var generator = new ItemsSourceGenerator(carouselView, initialItems: 50);

            layout.Children.Add(generator);

            var scrollToControl = new ScrollToIndexControl(carouselView, false);

            layout.Children.Add(scrollToControl);

            layout.Children.Add(carouselView);

            Grid.SetRow(scrollToControl, 1);
            Grid.SetRow(carouselView, 2);

            Content = layout;

            generator.GenerateItems();
        }
示例#2
0
        public CarouselItemsGallery()
        {
            var viewModel = new CarouselItemsGalleryViewModel();

            Title = $"CarouselView (Items)";

            var layout = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = GridLength.Star
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    }
                }
            };

            var itemsLayout =
                new ListItemsLayout(ItemsLayoutOrientation.Horizontal)
            {
                SnapPointsType      = SnapPointsType.MandatorySingle,
                SnapPointsAlignment = SnapPointsAlignment.Center
            };

            var itemTemplate = GetCarouselTemplate();

            var carouselView = new CarouselView
            {
                ItemsLayout      = itemsLayout,
                ItemTemplate     = itemTemplate,
                ItemsSource      = viewModel.Items,
                IsScrollAnimated = true,
                IsBounceEnabled  = true
            };

            layout.Children.Add(carouselView, 0, 0);

            var stacklayoutButtons = new StackLayout
            {
                Orientation = StackOrientation.Horizontal
            };

            var addItemButton = new Button
            {
                Text = "Add Item"
            };

            addItemButton.Clicked += (sender, e) =>
            {
                viewModel.Items.Add(new CarouselData
                {
                    Color = Color.Red,
                    Name  = $"{viewModel.Items.Count + 1}"
                });
                carouselView.Position = viewModel.Items.Count - 1;
            };

            var removeItemButton = new Button
            {
                Text = "Remove Item"
            };

            removeItemButton.Clicked += (sender, e) =>
            {
                if (viewModel.Items.Any())
                {
                    viewModel.Items.RemoveAt(viewModel.Items.Count - 1);
                }

                if (viewModel.Items.Count > 0)
                {
                    carouselView.Position = viewModel.Items.Count - 1;
                }
            };

            var clearItemsButton = new Button
            {
                Text = "Clear Items"
            };

            clearItemsButton.Clicked += (sender, e) =>
            {
                viewModel.Items.Clear();
            };

            stacklayoutButtons.Children.Add(addItemButton);
            stacklayoutButtons.Children.Add(removeItemButton);
            stacklayoutButtons.Children.Add(clearItemsButton);

            layout.Children.Add(stacklayoutButtons, 0, 1);

            Content        = layout;
            BindingContext = viewModel;
        }
        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 ListItemsLayout(orientation)
            {
                SnapPointsType      = SnapPointsType.MandatorySingle,
                SnapPointsAlignment = SnapPointsAlignment.Center
            };

            var itemTemplate = ExampleTemplates.CarouselTemplate();

            var carouselView = new CarouselView
            {
                ItemsLayout  = itemsLayout,
                ItemTemplate = itemTemplate,
                Position     = 2,
                //NumberOfSideItems = 1,
                Margin          = new Thickness(0, 10, 0, 40),
                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;

            layout.Children.Add(carouselView);

            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, "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);

            Grid.SetRow(positionControl, 1);
            Grid.SetRow(stacklayoutInfo, 2);
            Grid.SetRow(spacingModifier, 3);
            Grid.SetRow(carouselView, 4);

            Content = layout;
            generator.CollectionChanged += (sender, e) => {
                positionControl.UpdatePositionCount(generator.Count);
            };

            generator.GenerateItems();
        }
示例#4
0
 public ListViewLayout(ListItemsLayout itemsLayout, ItemSizingStrategy itemSizingStrategy) : base(itemsLayout, itemSizingStrategy)
 {
 }
示例#5
0
 public ListViewLayout(ListItemsLayout itemsLayout) : base(itemsLayout)
 {
 }
示例#6
0
 public static ListItemsLayout ItemsSpacing(this ListItemsLayout layout, double spacing)
 {
     layout.ItemSpacing = spacing;
     return(layout);
 }