Beispiel #1
0
        public SpacingGallery(IItemsLayout 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.Star
                    }
                }
            };

            var instructions = new Label
            {
                Text = "Use the control below to update the spacing between items."
            };

            if (itemsLayout is GridItemsLayout)
            {
                instructions.Text += " Format is '[vertical], [horizontal]'";
            }

            var itemTemplate = ExampleTemplates.SpacingTemplate();

            var collectionView = new CollectionView
            {
                ItemsLayout  = itemsLayout,
                ItemTemplate = itemTemplate,
                AutomationId = "collectionview",
                Margin       = 10
            };

            var generator       = new ItemsSourceGenerator(collectionView, initialItems: 20);
            var spacingModifier = new SpacingModifier(collectionView.ItemsLayout, "Update_Spacing");

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

            Grid.SetRow(instructions, 1);
            Grid.SetRow(spacingModifier, 2);
            Grid.SetRow(collectionView, 3);

            Content = layout;

            generator.GenerateItems();
        }
Beispiel #2
0
        public UngroupedReorderingGallery(IItemsLayout 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.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                }
            };

            var reorderCompletedLabel = new Label
            {
                Text = "ReorderCompleted (event): NA",
            };

            var itemTemplate = ExampleTemplates.SpacingTemplate();

            var collectionView = new CollectionView
            {
                ItemsLayout     = itemsLayout,
                ItemTemplate    = itemTemplate,
                AutomationId    = "collectionview",
                CanReorderItems = true
            };

            collectionView.ReorderCompleted += (sender, e) => reorderCompletedLabel.Text = $"ReorderCompleted (event): {DateTime.Now}";

            var generator = new ItemsSourceGenerator(collectionView, initialItems: 20, itemsSourceType: ItemsSourceType.ObservableCollection);

            var itemsSourceTypeSelector = new EnumSelector <ItemsSourceType>(() => generator.ItemsSourceType, sourceType => UpdateItemsSourceType(generator, sourceType, collectionView));

            var spacingModifier = new SpacingModifier(collectionView.ItemsLayout, "Update_Spacing");

            var reloadButton = new Button {
                Text = "Reload Current Source", AutomationId = "btnReload", HorizontalOptions = LayoutOptions.Start
            };

            reloadButton.Clicked += (sender, e) => ReloadItemsSource(collectionView);

            layout.Children.Add(generator);
            layout.Children.Add(itemsSourceTypeSelector);
            layout.Children.Add(spacingModifier);
            layout.Children.Add(reorderCompletedLabel);
            layout.Children.Add(reloadButton);
            layout.Children.Add(collectionView);

            Grid.SetRow(itemsSourceTypeSelector, 1);
            Grid.SetRow(spacingModifier, 2);
            Grid.SetRow(reorderCompletedLabel, 3);
            Grid.SetRow(reloadButton, 4);
            Grid.SetRow(collectionView, 5);

            Content = layout;

            generator.GenerateItems();
        }