示例#1
0
        public TextCodeCollectionViewGallery(IItemsLayout itemsLayout)
        {
            var layout = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                }
            };

            var collectionView = new CollectionView
            {
                ItemsLayout   = itemsLayout,
                SelectionMode = SelectionMode.Single,
                AutomationId  = "collectionview"
            };

            var generator = new ItemsSourceGenerator(collectionView);

            layout.Children.Add(generator);

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

            Content = layout;

            generator.GenerateItems();
        }
示例#2
0
        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();
        }
        public ObservableCollectionResetGallery()
        {
            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(3, ItemsLayoutOrientation.Vertical) as IItemsLayout;

            var itemTemplate = ExampleTemplates.PhotoTemplate();

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

            var generator = new ItemsSourceGenerator(collectionView, 100, ItemsSourceType.MultiTestObservableCollection);

            layout.Children.Add(generator);

            var resetter = new Resetter(collectionView);

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

            layout.Children.Add(collectionView);
            Grid.SetRow(collectionView, 2);

            Content = layout;

            generator.GenerateItems();
        }
示例#4
0
        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();
        }
示例#5
0
        public TemplateCodeCollectionViewGallery(IItemsLayout itemsLayout)
        {
            var layout = new Grid
            {
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                }
            };

            var itemTemplate = ExampleTemplates.PhotoTemplate();

            var collectionView = new CollectionView
            {
                ItemsLayout     = itemsLayout,
                ItemTemplate    = itemTemplate,
                AutomationId    = "collectionview",
                BackgroundColor = Colors.Red,
            };

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

            layout.Children.Add(generator);
            layout.Children.Add(collectionView);

            Grid.SetRow(collectionView, 1);

            Content = layout;

            generator.GenerateItems();
        }
示例#6
0
        public SnapPointsCodeGallery(ItemsLayout itemsLayout)
        {
            Title = $"Snap Points (Code, {itemsLayout})";

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

            itemsLayout.SnapPointsAlignment = SnapPointsAlignment.Start;
            itemsLayout.SnapPointsType      = SnapPointsType.None;

            var itemTemplate = ExampleTemplates.SnapPointsTemplate();

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

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

            var snapPointsTypeSelector = new EnumSelector <SnapPointsType>(() => itemsLayout.SnapPointsType,
                                                                           type => itemsLayout.SnapPointsType = type);

            var snapPointsAlignmentSelector = new EnumSelector <SnapPointsAlignment>(() => itemsLayout.SnapPointsAlignment,
                                                                                     type => itemsLayout.SnapPointsAlignment = type);

            var flowDirectionSelector = new EnumSelector <FlowDirection>(() => layout.FlowDirection,
                                                                         type => layout.FlowDirection = type);

            layout.Children.Add(generator);
            layout.Children.Add(snapPointsTypeSelector);
            layout.Children.Add(snapPointsAlignmentSelector);
            layout.Children.Add(flowDirectionSelector);
            layout.Children.Add(collectionView);

            Grid.SetRow(snapPointsTypeSelector, 1);
            Grid.SetRow(snapPointsAlignmentSelector, 2);
            Grid.SetRow(flowDirectionSelector, 3);
            Grid.SetRow(collectionView, 4);

            Content = layout;

            generator.GenerateItems();
        }
示例#7
0
        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();
            }
        }
示例#8
0
        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();
        }
        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 LinearItemsLayout(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();
        }