public IndicatorCodeGallery() { Title = "IndicatorView Gallery"; On <iOS>().SetLargeTitleDisplay(LargeTitleDisplayMode.Never); var nItems = 10; 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 }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = ExampleTemplates.CarouselTemplate(); var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, BackgroundColor = Color.LightGray, AutomationId = "TheCarouselView" }; layout.Children.Add(carouselView); var generator = new ItemsSourceGenerator(carouselView, nItems, ItemsSourceType.ObservableCollection); layout.Children.Add(generator); generator.GenerateItems(); var indicatorView = new IndicatorView { HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(12, 6, 12, 12), IndicatorColor = Color.Gray, SelectedIndicatorColor = Color.Black, IndicatorsShape = IndicatorShape.Square, AutomationId = "TheIndicatorView" }; carouselView.IndicatorView = indicatorView; layout.Children.Add(indicatorView); var stckColors = new StackLayout { Orientation = StackOrientation.Horizontal }; stckColors.Children.Add(new Label { VerticalOptions = LayoutOptions.Center, Text = "IndicatorColor" }); var colors = new List <string> { "Black", "Blue", "Red" }; var colorsPicker = new Xamarin.Forms.Picker { ItemsSource = colors, WidthRequest = 150 }; colorsPicker.SelectedIndex = 0; colorsPicker.SelectedIndexChanged += (s, e) => { var selectedIndex = colorsPicker.SelectedIndex; switch (selectedIndex) { case 0: indicatorView.IndicatorColor = Color.Black; break; case 1: indicatorView.IndicatorColor = Color.Blue; break; case 2: indicatorView.IndicatorColor = Color.Red; break; } }; stckColors.Children.Add(colorsPicker); layout.Children.Add(stckColors); var stckTemplate = new StackLayout { Orientation = StackOrientation.Horizontal }; stckTemplate.Children.Add(new Label { VerticalOptions = LayoutOptions.Center, Text = "IndicatorTemplate" }); var templates = new List <string> { "Circle", "Square", "Template" }; var templatePicker = new Xamarin.Forms.Picker { ItemsSource = templates, WidthRequest = 150, TextColor = Color.Black }; templatePicker.SelectedIndexChanged += (s, e) => { var selectedIndex = templatePicker.SelectedIndex; switch (selectedIndex) { case 0: indicatorView.IndicatorTemplate = null; indicatorView.IndicatorsShape = IndicatorShape.Circle; break; case 1: indicatorView.IndicatorTemplate = null; indicatorView.IndicatorsShape = IndicatorShape.Square; break; case 2: indicatorView.IndicatorTemplate = ExampleTemplates.IndicatorTemplate(); break; } }; templatePicker.SelectedIndex = 0; stckTemplate.Children.Add(templatePicker); layout.Children.Add(stckTemplate); var stckSize = new StackLayout { Orientation = StackOrientation.Horizontal }; stckSize.Children.Add(new Label { VerticalOptions = LayoutOptions.Center, Text = "Indicator Size" }); indicatorView.IndicatorSize = 10; var sizeSlider = new Xamarin.Forms.Slider { WidthRequest = 150, Value = indicatorView.IndicatorSize, MaximumTrackColor = Color.Gray, Maximum = 20, MinimumTrackColor = Color.LightGray, Minimum = 1 }; sizeSlider.ValueChanged += (s, e) => { var indicatorSize = sizeSlider.Value; indicatorView.IndicatorSize = indicatorSize; }; stckSize.Children.Add(sizeSlider); layout.Children.Add(stckSize); Grid.SetRow(generator, 0); Grid.SetRow(stckColors, 1); Grid.SetRow(stckTemplate, 2); Grid.SetRow(stckSize, 3); Grid.SetRow(carouselView, 4); Grid.SetRow(indicatorView, 5); Content = layout; }
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(); }