public PropagateCodeGallery(IItemsLayout itemsLayout, int itemsCount = 2)
        {
            Title = $"Propagate FlowDirection=RTL";

            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.Star
                    }
                },
                FlowDirection = FlowDirection.RightToLeft,
                Visual        = VisualMarker.Material
            };

            var itemTemplate = ExampleTemplates.PropagationTemplate();

            var emptyView = ExampleTemplates.PropagationTemplate().CreateContent() as View;


            var collectionView = new CollectionView
            {
                ItemsLayout  = itemsLayout,
                ItemTemplate = itemTemplate,
                EmptyView    = emptyView
            };

            var generator = new ItemsSourceGenerator(collectionView, initialItems: itemsCount);

            layout.Children.Add(generator);
            var instructions = new Label();

            UpdateInstructions(layout, instructions, itemsCount == 0);
            Grid.SetRow(instructions, 2);
            layout.Children.Add(instructions);

            var switchLabel = new Label {
                Text = "Toggle FlowDirection"
            };
            var switchLayout = new StackLayout {
                Orientation = StackOrientation.Horizontal
            };
            var updateSwitch = new Switch {
            };

            updateSwitch.Toggled += (sender, args) =>
            {
                layout.FlowDirection = layout.FlowDirection == FlowDirection.RightToLeft
                                        ? FlowDirection.LeftToRight
                                        : FlowDirection.RightToLeft;

                UpdateInstructions(layout, instructions, itemsCount == 0);
            };

            switchLayout.Children.Add(switchLabel);
            switchLayout.Children.Add(updateSwitch);

            Grid.SetRow(switchLayout, 1);
            layout.Children.Add(switchLayout);

            layout.Children.Add(collectionView);

            Grid.SetRow(collectionView, 3);

            Content = layout;

            generator.GenerateItems();
        }
Exemplo n.º 2
0
        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 Xamarin.Forms.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();
        }
Exemplo n.º 3
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 LinearItemsLayout(orientation) as IItemsLayout;

            var itemTemplate = ExampleTemplates.PhotoTemplate();

            var collectionView = new CollectionView {
                ItemsLayout  = itemsLayout, ItemTemplate = itemTemplate,
                AutomationId = "collectionview", Header = "This is the header"
            };

            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();
            }
        }