protected override void Init() { var layout = new StackLayout(); var instructions = new Label { Margin = new Thickness(6), Text = "The CarouselView below should render 5 items." }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = GetCarouselTemplate() }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); layout.Children.Add(instructions); layout.Children.Add(carouselView); Content = layout; }
protected override void Init() { var layout = new StackLayout(); var instructions = new Label { Margin = new Thickness(6), Text = "Change the CarouselView FlowDirection and verify that it works correctly." }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var carouselView = new CarouselView { FlowDirection = FlowDirection.RightToLeft, ItemsLayout = itemsLayout, ItemTemplate = GetCarouselTemplate() }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); var flowDirectionButton = new Button { Text = "Change FlowDirection" }; var flowDirectionLabel = new Label { Text = carouselView.FlowDirection.ToString() }; layout.Children.Add(instructions); layout.Children.Add(carouselView); layout.Children.Add(flowDirectionButton); layout.Children.Add(flowDirectionLabel); flowDirectionButton.Clicked += (sender, args) => { if (carouselView.FlowDirection == FlowDirection.RightToLeft) { carouselView.FlowDirection = FlowDirection.LeftToRight; flowDirectionLabel.Text = "LeftToRight"; } else { carouselView.FlowDirection = FlowDirection.RightToLeft; flowDirectionLabel.Text = "RightToLeft"; } }; Content = layout; }
protected override void Init() { var layout = new StackLayout(); var instructions = new Label { Margin = new Thickness(6), BackgroundColor = Color.Black, TextColor = Color.White, Text = "Press the Button to update the ItemsSource of the CarouselView below. After updating, verify that the IndicatorView is still visible. If it is visible, the test has passed." }; var updateButton = new Button { Text = "Update ItemsSource" }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = GetCarouselTemplate() }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); var indicatorView = new IndicatorView { IndicatorColor = Color.Red, SelectedIndicatorColor = Color.Green, IndicatorTemplate = GetIndicatorTemplate(), HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 0, 0, 24) }; carouselView.IndicatorView = indicatorView; layout.Children.Add(instructions); layout.Children.Add(updateButton); layout.Children.Add(carouselView); layout.Children.Add(indicatorView); Content = layout; updateButton.Clicked += (sender, args) => { var vm = (Issue8693ViewModel)BindingContext; vm.LoadItems(); }; }
public ExtendedCarousel() { HorizontalScrollBarVisibility = ScrollBarVisibility.Never; VerticalScrollBarVisibility = ScrollBarVisibility.Never; IsScrollAnimated = true; ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsAlignment = SnapPointsAlignment.Center, SnapPointsType = SnapPointsType.MandatorySingle }; }
public void SnapPointsDoNotCrashOnOlderAPIs() { var cv = new CollectionView(); var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical) { SnapPointsType = SnapPointsType.Mandatory }; cv.ItemsLayout = itemsLayout; // Creating the renderer is enough to cause the ClassNotFoundException on older APIs GetRenderer(cv).Dispose(); }
public async Task SnapPointsDoNotCrashOnOlderAPIs() { var cv = new CollectionView(); var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical) { SnapPointsType = SnapPointsType.Mandatory }; cv.ItemsLayout = itemsLayout; // Creating the renderer is enough to cause the ClassNotFoundException on older APIs await Device.InvokeOnMainThreadAsync(() => { GetRenderer(cv).Dispose(); }); }
public async Task SnapPointsDoNotCrashOnOlderAPIs() { var cv = new Microsoft.Maui.Controls.CollectionView(); var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical) { SnapPointsType = SnapPointsType.Mandatory }; cv.ItemsLayout = itemsLayout; // Creating the renderer is enough to cause the ClassNotFoundException on older APIs await cv.Dispatcher.DispatchAsync(() => { GetRenderer(cv).Dispose(); }); }
public override async void OnNavigatedTo(INavigationParameters parameters) { if (string.IsNullOrWhiteSpace(Preferences.Get("search", string.Empty))) { AllShows = await graphQL.MovieQuery("allShows", "thumbnail", "title"); ColViewLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); } for (int i = 0; i < AllShows.Count; i++) { AllShows[i].ShowInfoCommand = new DelegateCommand <MovieModel>(async(show) => await ShowPopup(show)); } IsSearchVisible = false; }
public ReferringSitesCollectionView() { AutomationId = ReferringSitesPageAutomationIds.CollectionView; BackgroundColor = Color.Transparent; ItemTemplate = new ReferringSitesDataTemplate(); SelectionMode = SelectionMode.Single; ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879 Header = Device.RuntimePlatform is Device.iOS ? null : new BoxView { HeightRequest = ReferringSitesDataTemplate.BottomPadding }; Footer = Device.RuntimePlatform is Device.iOS ? null : new BoxView { HeightRequest = ReferringSitesDataTemplate.TopPadding }; EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView); }
public ReferringSitesCollectionView() { AutomationId = ReferringSitesPageAutomationIds.CollectionView; BackgroundColor = Color.Transparent; ItemTemplate = new ReferringSitesDataTemplateSelector(); SelectionMode = SelectionMode.Single; ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); //iOS Header + Footer break CollectionView after Refresh bug: https://github.com/xamarin/Xamarin.Forms/issues/9879 Header = Device.RuntimePlatform is Device.iOS ? null : new BoxView { HeightRequest = ReferringSitesDataTemplateSelector.BottomPadding }; Footer = Device.RuntimePlatform is Device.iOS ? null : new BoxView { HeightRequest = ReferringSitesDataTemplateSelector.TopPadding }; EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView); }
public void BindingContextPropagatesLayouts() { var bindingContext = new object(); var itemsView = new StructuredItemsView(); itemsView.BindingContext = bindingContext; var linearItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal); itemsView.ItemsLayout = linearItemsLayout; // BindingContext is set when ItemsLayout is set Assert.AreEqual(itemsView.BindingContext, linearItemsLayout.BindingContext); // BindingContext is updated when BindingContext on ItemsView is changed bindingContext = new object(); itemsView.BindingContext = bindingContext; Assert.AreEqual(itemsView.BindingContext, linearItemsLayout.BindingContext); }
public CarouselItemsGallery() { var viewModel = new CarouselItemsGalleryViewModel(); Title = $"CarouselView (Indicators)"; var grid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, ItemsSource = viewModel.Items, IsScrollAnimated = true, IsBounceEnabled = true, EmptyView = "This is the empty view", PeekAreaInsets = new Thickness(50) }; var absolute = new AbsoluteLayout(); absolute.Children.Add(carouselView, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); var indicators = new IndicatorView { Margin = new Thickness(15, 20), IndicatorColor = Color.Gray, SelectedIndicatorColor = Color.Black, IndicatorsShape = IndicatorShape.Square }; //carouselView.IndicatorView = indicators; absolute.Children.Add(indicators, new Rectangle(.5, 1, -1, -1), AbsoluteLayoutFlags.PositionProportional); grid.Children.Add(absolute, 0, 0); var stacklayoutButtons = new StackLayout { Orientation = StackOrientation.Horizontal }; var addItemButton = new Button { Text = "Add Item" }; addItemButton.Clicked += (sender, e) => { viewModel.Items.Add(new CarouselData { Color = Color.Red, Name = $"{viewModel.Items.Count + 1}" }); carouselView.Position = viewModel.Items.Count - 1; }; var removeItemButton = new Button { Text = "Remove Item" }; removeItemButton.Clicked += (sender, e) => { if (viewModel.Items.Any()) { viewModel.Items.RemoveAt(viewModel.Items.Count - 1); } if (viewModel.Items.Count > 0) { carouselView.Position = viewModel.Items.Count - 1; } }; var clearItemsButton = new Button { Text = "Clear Items" }; clearItemsButton.Clicked += (sender, e) => { viewModel.Items.Clear(); }; stacklayoutButtons.Children.Add(addItemButton); stacklayoutButtons.Children.Add(removeItemButton); stacklayoutButtons.Children.Add(clearItemsButton); grid.Children.Add(stacklayoutButtons, 0, 1); Content = grid; BindingContext = viewModel; }
public CollectionCarouselViewGallery() { Title = "Working with ObservableCollections and CarouselView"; BindingContext = new CollectionCarouselViewGalleryViewModel(); var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { HeightRequest = 300, BackgroundColor = Color.Pink, ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, IsScrollAnimated = true, IsBounceEnabled = true, AutomationId = "TheCarouselView", }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); var scroll = new ScrollView(); var stack = new StackLayout(); scroll.Content = stack; var lblPosition = new Label { HorizontalOptions = LayoutOptions.Center, BindingContext = carouselView, AutomationId = "lblPosition" }; var lblCenterIndex = new Label { HorizontalOptions = LayoutOptions.Center, BindingContext = carouselView, AutomationId = "lblCenterIndex" }; lblPosition.SetBinding(Label.TextProperty, nameof(CarouselView.Position)); carouselView.Scrolled += (s, e) => { lblCenterIndex.Text = $"First {e.FirstVisibleItemIndex} CenterIndex: {e.CenterItemIndex} Last: {e.LastVisibleItemIndex}"; }; var clearButton = new Button { Text = "Clear" }; clearButton.SetBinding(Button.CommandProperty, "ClearCommand"); var newObservableButton = new Button { Text = "Set new ObservableCollection", AutomationId = "btnNewObservable" }; newObservableButton.SetBinding(Button.CommandProperty, "NewObservableCommand"); var addObservableButton = new Button { Text = "Add new Items to ObservableCollection", AutomationId = "btnAddObservable" }; addObservableButton.SetBinding(Button.CommandProperty, "NewItemsObservableCommand"); var threadObservableButton = new Button { Text = "Use ObservableCollection (Threads)" }; threadObservableButton.SetBinding(Button.CommandProperty, "TheadCommand"); stack.Children.Add(lblPosition); stack.Children.Add(lblCenterIndex); stack.Children.Add(clearButton); stack.Children.Add(newObservableButton); stack.Children.Add(addObservableButton); stack.Children.Add(threadObservableButton); layout.Children.Add(carouselView, 0, 0); layout.Children.Add(scroll, 0, 1); Content = layout; }
public CollectionCarouselViewGallery() { Title = "Working with ObservableCollections and CarouselView"; BindingContext = new CollectionCarouselViewGalleryViewModel(); var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { HeightRequest = 300, BackgroundColor = Color.Pink, ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, IsScrollAnimated = true, IsBounceEnabled = true }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, "Items"); var scroll = new ScrollView(); var stack = new StackLayout(); scroll.Content = stack; var clearButton = new Button { Text = "Clear" }; clearButton.SetBinding(Button.CommandProperty, "ClearCommand"); var newObservableButton = new Button { Text = "Set new ObservableCollection" }; newObservableButton.SetBinding(Button.CommandProperty, "NewObservableCommand"); var addObservableButton = new Button { Text = "Add new Items to ObservableCollection" }; addObservableButton.SetBinding(Button.CommandProperty, "NewItemsObservableCommand"); var threadObservableButton = new Button { Text = "Use ObservableCollection (Threads)" }; threadObservableButton.SetBinding(Button.CommandProperty, "TheadCommand"); stack.Children.Add(clearButton); stack.Children.Add(newObservableButton); stack.Children.Add(addObservableButton); stack.Children.Add(threadObservableButton); layout.Children.Add(carouselView, 0, 0); layout.Children.Add(scroll, 0, 1); Content = layout; }
public ListViewLayout(LinearItemsLayout itemsLayout, ItemSizingStrategy itemSizingStrategy) : base(itemsLayout, itemSizingStrategy) { }
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 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 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 = 25; var sizeSlider = new Slider { WidthRequest = 150, Value = indicatorView.IndicatorSize, Maximum = 50, }; 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 CarouselItemsGallery() { var viewModel = new CarouselItemsGalleryViewModel(); Title = $"CarouselView (Items)"; var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, ItemsSource = viewModel.Items, IsScrollAnimated = true, IsBounceEnabled = true, EmptyView = "This is the empty view" }; layout.Children.Add(carouselView, 0, 0); var stacklayoutButtons = new StackLayout { Orientation = StackOrientation.Horizontal }; var addItemButton = new Button { Text = "Add Item" }; addItemButton.Clicked += (sender, e) => { viewModel.Items.Add(new CarouselData { Color = Color.Red, Name = $"{viewModel.Items.Count + 1}" }); carouselView.Position = viewModel.Items.Count - 1; }; var removeItemButton = new Button { Text = "Remove Item" }; removeItemButton.Clicked += (sender, e) => { if (viewModel.Items.Any()) { viewModel.Items.RemoveAt(viewModel.Items.Count - 1); } if (viewModel.Items.Count > 0) { carouselView.Position = viewModel.Items.Count - 1; } }; var clearItemsButton = new Button { Text = "Clear Items" }; clearItemsButton.Clicked += (sender, e) => { viewModel.Items.Clear(); }; stacklayoutButtons.Children.Add(addItemButton); stacklayoutButtons.Children.Add(removeItemButton); stacklayoutButtons.Children.Add(clearItemsButton); layout.Children.Add(stacklayoutButtons, 0, 1); Content = layout; BindingContext = viewModel; }
public static LinearItemsLayout ItemSpacing(this LinearItemsLayout layout, double spacing) { layout.ItemSpacing = spacing; return(layout); }
public static T ItemsLayout <T>(this T carouselview, LinearItemsLayout itemsLayout) where T : IRxCarouselView { carouselview.ItemsLayout = itemsLayout; return(carouselview); }
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 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(); }
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 }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; var itemTemplate = ExampleTemplates.CarouselTemplate(); _carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, BackgroundColor = Colors.LightGray, AutomationId = "TheCarouselView" }; layout.Children.Add(_carouselView); var generator = new ItemsSourceGenerator(_carouselView, nItems, ItemsSourceType.ObservableCollection); layout.Children.Add(generator); generator.GenerateItems(); _carouselView.PropertyChanged += CarouselViewPropertyChanged; (_carouselView.ItemsSource as ObservableCollection <CollectionViewGalleryTestItem>).CollectionChanged += IndicatorCodeGalleryCollectionChanged; var indicatorView = new IndicatorView { HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(12, 6, 12, 12), IndicatorColor = Colors.Gray, SelectedIndicatorColor = Colors.Black, IndicatorsShape = IndicatorShape.Square, AutomationId = "TheIndicatorView", Count = 5, }; _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 Picker { ItemsSource = colors, WidthRequest = 150 }; colorsPicker.SelectedIndex = 0; colorsPicker.SelectedIndexChanged += (s, e) => { var selectedIndex = colorsPicker.SelectedIndex; switch (selectedIndex) { case 0: indicatorView.IndicatorColor = Colors.Black; break; case 1: indicatorView.IndicatorColor = Colors.Blue; break; case 2: indicatorView.IndicatorColor = Colors.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 Picker { ItemsSource = templates, WidthRequest = 150, TextColor = Colors.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 = 25; var sizeSlider = new Slider { WidthRequest = 150, Value = indicatorView.IndicatorSize, Maximum = 50, }; 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, 6); var layoutBtn = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, }; var btnRemove = new Button { Text = "DEL First", FontSize = 8, AutomationId = "btnRemoveFirst", BackgroundColor = Colors.LightGray, Padding = new Thickness(5), Command = new Command(() => { var items = (_carouselView.ItemsSource as ObservableCollection <CollectionViewGalleryTestItem>); items.Remove(items[0]); }) }; _btnPrev = new Button { Text = "Prev", FontSize = 8, AutomationId = "btnPrev", BackgroundColor = Colors.LightGray, Padding = new Thickness(5), Command = new Command(() => { _carouselView.Position--; }, () => { return(_carouselView.Position > 0); }) }; _btnNext = new Button { Text = "Next", FontSize = 8, AutomationId = "btnNext", BackgroundColor = Colors.LightGray, Padding = new Thickness(5), Command = new Command(() => { _carouselView.Position++; }, () => { var items = (_carouselView.ItemsSource as ObservableCollection <CollectionViewGalleryTestItem>); return(_carouselView.Position < items.Count - 1); }) }; var btnRemoveLast = new Button { Text = "DEL Last", FontSize = 8, AutomationId = "btnRemoveLast", BackgroundColor = Colors.LightGray, Padding = new Thickness(5), Command = new Command(() => { var items = (_carouselView.ItemsSource as ObservableCollection <CollectionViewGalleryTestItem>); var indexToRemove = items.Count - 1; items.Remove(items[indexToRemove]); }) }; layoutBtn.Children.Add(btnRemove); layoutBtn.Children.Add(_btnPrev); layoutBtn.Children.Add(_btnNext); layoutBtn.Children.Add(btnRemoveLast); layout.Children.Add(layoutBtn); Grid.SetRow(layoutBtn, 5); Content = layout; }
public CarouselSnapGallery() { On <iOS>().SetLargeTitleDisplay(LargeTitleDisplayMode.Never); var viewModel = new CarouselItemsGalleryViewModel(false, false); Title = $"CarouselView Snap Options"; var layout = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } } }; var snapPointsStack = new StackLayout { Margin = new Thickness(12) }; var snapPointsLabel = new Label { FontSize = 10, Text = "SnapPointsType:" }; var snapPointsTypes = Enum.GetNames(typeof(SnapPointsType)).Select(b => b).ToList(); var snapPointsTypePicker = new Picker { ItemsSource = snapPointsTypes, SelectedItem = snapPointsTypes[1] }; snapPointsStack.Children.Add(snapPointsLabel); snapPointsStack.Children.Add(snapPointsTypePicker); layout.Children.Add(snapPointsStack, 0, 0); var snapPointsAlignmentsStack = new StackLayout { Margin = new Thickness(12) }; var snapPointsAlignmentsLabel = new Label { FontSize = 10, Text = "SnapPointsAlignment:" }; var snapPointsAlignments = Enum.GetNames(typeof(SnapPointsAlignment)).Select(b => b).ToList(); var snapPointsAlignmentPicker = new Picker { ItemsSource = snapPointsAlignments, SelectedItem = snapPointsAlignments[0] }; snapPointsAlignmentsStack.Children.Add(snapPointsAlignmentsLabel); snapPointsAlignmentsStack.Children.Add(snapPointsAlignmentPicker); layout.Children.Add(snapPointsAlignmentsStack, 0, 1); var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.Mandatory, SnapPointsAlignment = SnapPointsAlignment.Start }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { ItemsSource = viewModel.Items, ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, BackgroundColor = Color.LightGray, PeekAreaInsets = new Thickness(0, 0, 100, 0), Margin = new Thickness(12), AutomationId = "TheCarouselView" }; layout.Children.Add(carouselView, 0, 2); snapPointsTypePicker.SelectedIndexChanged += (sender, e) => { if (carouselView.ItemsLayout is LinearItemsLayout linearItemsLayout) { Enum.TryParse(snapPointsTypePicker.SelectedItem.ToString(), out SnapPointsType snapPointsType); linearItemsLayout.SnapPointsType = snapPointsType; } }; snapPointsAlignmentPicker.SelectedIndexChanged += (sender, e) => { if (carouselView.ItemsLayout is LinearItemsLayout linearItemsLayout) { Enum.TryParse(snapPointsAlignmentPicker.SelectedItem.ToString(), out SnapPointsAlignment snapPointsAlignment); linearItemsLayout.SnapPointsAlignment = snapPointsAlignment; } }; Content = layout; BindingContext = viewModel; }
public CarouselItemsGallery(bool startEmptyCollection = false, bool setCollectionWithAsync = false, bool useNativeIndicators = false, bool setPositionOnConstructor = false, bool setPositionOnAppearing = false, bool useScrollAnimated = true) { _viewModel = new CarouselItemsGalleryViewModel(startEmptyCollection, setCollectionWithAsync); _setPositionOnAppering = setPositionOnAppearing; if (setPositionOnConstructor) { _viewModel.CarouselPosition = 3; } Title = $"CarouselView (Indicators)"; var grid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } } }; var itemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center, ItemSpacing = 8 }; var itemTemplate = GetCarouselTemplate(); var carouselView = new CarouselView { ItemsLayout = itemsLayout, ItemTemplate = itemTemplate, IsScrollAnimated = useScrollAnimated, IsBounceEnabled = true, EmptyView = "This is the empty view", PeekAreaInsets = new Thickness(50), }; carouselView.SetBinding(CarouselView.ItemsSourceProperty, nameof(_viewModel.Items)); carouselView.SetBinding(CarouselView.PositionProperty, nameof(_viewModel.CarouselPosition)); var absolute = new AbsoluteLayout(); absolute.Children.Add(carouselView, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); var indicators = new IndicatorView { Margin = new Thickness(15, 20), IndicatorColor = Colors.Gray, SelectedIndicatorColor = Colors.Black, IndicatorsShape = IndicatorShape.Square }; if (!useNativeIndicators) { indicators.IndicatorTemplate = new DataTemplate(() => { return(new Image { Source = new FontImageSource { FontFamily = DefaultFontFamily(), Glyph = "\uf30c", }, }); }); } carouselView.IndicatorView = indicators; absolute.Children.Add(indicators, new Rectangle(.5, 1, -1, -1), AbsoluteLayoutFlags.PositionProportional); grid.Children.Add(absolute, 0, 0); var stacklayoutButtons = new StackLayout { Orientation = StackOrientation.Horizontal }; var addItemButton = new Button { Text = "Add Item" }; addItemButton.Clicked += (sender, e) => { _viewModel.Items.Add(new CarouselData { Color = Colors.Red, Name = $"{_viewModel.Items.Count + 1}" }); _viewModel.CarouselPosition = _viewModel.Items.Count - 1; }; var removeItemButton = new Button { Text = "Remove Item" }; removeItemButton.Clicked += (sender, e) => { if (_viewModel.Items.Any()) { _viewModel.Items.RemoveAt(_viewModel.Items.Count - 1); } if (_viewModel.Items.Count > 0) { _viewModel.CarouselPosition = _viewModel.Items.Count - 1; } }; var clearItemsButton = new Button { Text = "Clear Items" }; clearItemsButton.Clicked += (sender, e) => { _viewModel.Items.Clear(); }; var lbl = new Label { AutomationId = "lblPosition" }; lbl.SetBinding(Label.TextProperty, nameof(CarouselView.Position)); lbl.BindingContext = carouselView; stacklayoutButtons.Children.Add(addItemButton); stacklayoutButtons.Children.Add(removeItemButton); stacklayoutButtons.Children.Add(clearItemsButton); stacklayoutButtons.Children.Add(lbl); grid.Children.Add(stacklayoutButtons, 0, 1); Content = grid; BindingContext = _viewModel; }
public static CarouselView ItemsLayout(this CarouselView carousel, LinearItemsLayout layout) { carousel.ItemsLayout = layout; return(carousel); }