Beispiel #1
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();
        }
Beispiel #2
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;
        }
Beispiel #3
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;
        }