public VariableSizeTemplateGridGallery(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.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    }
                }
            };

            var itemsLayout = new GridItemsLayout(2, orientation);

            var itemTemplate = ExampleTemplates.VariableSizeTemplate();

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

            var generator = new ItemsSourceGenerator(collectionView, 100);

            var explanation = new Label();

            UpdateExplanation(explanation, collectionView.ItemSizingStrategy);

            var sizingStrategySelector = new EnumSelector <ItemSizingStrategy>(() => collectionView.ItemSizingStrategy,
                                                                               mode => {
                collectionView.ItemSizingStrategy = mode;
                UpdateExplanation(explanation, collectionView.ItemSizingStrategy);
            });

            layout.Children.Add(generator);

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

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

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

            Content = layout;

            generator.GenerateItems();
        }
        public SelectionModeGallery()
        {
            InitializeComponent();

            CollectionView.ItemTemplate = ExampleTemplates.PhotoTemplate();
            CollectionView.ItemsSource  = _demoFilteredItemSource.Items;

            var selectionModeSelector = new EnumSelector <SelectionMode>(() => CollectionView.SelectionMode,
                                                                         mode => CollectionView.SelectionMode = mode);

            Grid.Children.Add(selectionModeSelector);

            CollectionView.SelectionChanged       += CollectionViewOnSelectionChanged;
            CollectionView.SelectionChangedCommand = new Command(UpdateSelectionInfoCommand);

            UpdateSelectionInfo(Enumerable.Empty <CollectionViewGalleryTestItem>(), Enumerable.Empty <CollectionViewGalleryTestItem>());
            UpdateSelectionInfoCommand();
        }
        public ScrollModeTestGallery(IItemsLayout itemsLayout = null, Func <DataTemplate> dataTemplate = null, Func <CollectionView> createCollectionView = null)
        {
            InitializeComponent();

            _collectionView             = createCollectionView == null ? new CollectionView() : createCollectionView();
            _collectionView.ItemsLayout = itemsLayout ?? LinearItemsLayout.Vertical;

            var scrollModeSelector = new EnumSelector <ItemsUpdatingScrollMode>(() => _collectionView.ItemsUpdatingScrollMode,
                                                                                mode => _collectionView.ItemsUpdatingScrollMode = mode, "SelectScrollMode");

            Grid.Children.Add(scrollModeSelector);


            Grid.Children.Add(_collectionView);
            Grid.SetRow(_collectionView, 5);

            _collectionView.ItemTemplate = dataTemplate == null?ExampleTemplates.PhotoTemplate() : dataTemplate();

            _collectionView.ItemsSource = _demoFilteredItemSource.Items;
        }
        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();
        }
Exemplo n.º 5
0
        public ScrollToIndexControl(ItemsView itemsView, bool showPositionSelector = true)
        {
            _itemsView = itemsView;

            var layout = new StackLayout {
                Margin = 3
            };

            var indexLabel = new Label {
                Text = "Scroll To Index: ", VerticalTextAlignment = TextAlignment.Center
            };

            _entry = new Entry {
                Keyboard = Keyboard.Numeric, Text = "0", WidthRequest = 200
            };
            var indexButton = new Button {
                Text = "Go"
            };

            indexButton.Clicked += ScrollTo;

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

            row1.Children.Add(indexLabel);
            row1.Children.Add(_entry);
            row1.Children.Add(indexButton);

            layout.Children.Add(row1);

            var animateLabel = new Label {
                Text = "Animate: ", VerticalTextAlignment = TextAlignment.Center
            };

            _animateSwitch = new Switch {
                IsToggled = true
            };

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

            row2.Children.Add(animateLabel);
            row2.Children.Add(_animateSwitch);

            _currentIndex = new Label
            {
                Text                    = _index.ToString(),
                WidthRequest            = 100,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center
            };

            var forwardButton = new Button {
                Text = "Advance 1 >>"
            };

            forwardButton.Clicked += (sender, args) =>
            {
                _index             = _index + 1;
                _currentIndex.Text = _index.ToString();
                ScrollToIndex(_index);
            };

            var backButton = new Button {
                Text = "<< Back 1"
            };

            backButton.Clicked += (sender, args) =>
            {
                if (_index > 0)
                {
                    _index             = _index - 1;
                    _currentIndex.Text = _index.ToString();
                    ScrollToIndex(_index);
                }
            };

            layout.Children.Add(row2);

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

            row3.Children.Add(backButton);
            row3.Children.Add(_currentIndex);
            row3.Children.Add(forwardButton);

            layout.Children.Add(row3);

            if (showPositionSelector)
            {
                var row4 = new StackLayout {
                    Orientation = StackOrientation.Horizontal
                };
                var scrollPositionSelector = new EnumSelector <ScrollToPosition>(() => _currentScrollToPosition,
                                                                                 type => _currentScrollToPosition = type);
                row4.Children.Add(scrollPositionSelector);

                layout.Children.Add(row4);
            }

            Content = layout;
        }
Exemplo n.º 6
0
        public ScrollToItemControl(ItemsView itemsView, bool showPositionSelector = true)
        {
            _itemsView = itemsView;

            var layout = new StackLayout {
                Margin = 3
            };

            _itemsView.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == ItemsView.ItemsSourceProperty.PropertyName)
                {
                    var items = new List <object>();
                    foreach (var item in itemsView.ItemsSource)
                    {
                        items.Add(item);
                    }

                    _picker.ItemsSource = items;
                }
            };

            var indexLabel = new Label {
                Text = "Scroll To Item: ", VerticalTextAlignment = TextAlignment.Center
            };

            _picker = new Picker {
                WidthRequest = 200
            };
            var indexButton = new Button {
                Text = "Go"
            };

            indexButton.Clicked += ScrollTo;

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

            row1.Children.Add(indexLabel);
            row1.Children.Add(_picker);
            row1.Children.Add(indexButton);

            layout.Children.Add(row1);

            var animateLabel = new Label {
                Text = "Animate: ", VerticalTextAlignment = TextAlignment.Center
            };

            _animateSwitch = new Switch {
                IsToggled = true
            };

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

            row2.Children.Add(animateLabel);
            row2.Children.Add(_animateSwitch);

            layout.Children.Add(row2);

            if (showPositionSelector)
            {
                var row4 = new StackLayout {
                    Orientation = StackOrientation.Horizontal
                };

                var scrollPositionSelector = new EnumSelector <ScrollToPosition>(() => _currentScrollToPosition,
                                                                                 type => _currentScrollToPosition = type);
                row4.Children.Add(scrollPositionSelector);

                layout.Children.Add(row4);
            }

            Content = layout;
        }