private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     _carousel = this.FindControl<Carousel>("carousel");
     _left = this.FindControl<Button>("left");
     _right = this.FindControl<Button>("right");
     _transition = this.FindControl<DropDown>("transition");
 }
Example #2
0
        private static TabItem ImagesTab()
        {
            var imageCarousel = new Carousel
            {
                Width = 400,
                Height = 400,
                Transition = new PageSlide(TimeSpan.FromSeconds(0.25)),
                Items = new[]
                {
                    new Image { Source = new Bitmap(GetImage("github_icon.png")),  Width = 400, Height = 400 },
                    new Image { Source = new Bitmap(GetImage("pattern.jpg")), Width = 400, Height = 400 },
                }
            };

            var next = new Button
            {
                VerticalAlignment = VerticalAlignment.Center,
                Padding = new Thickness(20),
                Content = new Avalonia.Controls.Shapes.Path
                {
                    Data = StreamGeometry.Parse("M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"),
                    Fill = Brushes.Black
                }
            };

            var prev = new Button
            {
                VerticalAlignment = VerticalAlignment.Center,
                Padding = new Thickness(20),
                Content = new Avalonia.Controls.Shapes.Path
                {
                    Data = StreamGeometry.Parse("M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"),
                    Fill = Brushes.Black
                }
            };

            prev.Click += (s, e) =>
            {
                if (imageCarousel.SelectedIndex == 0)
                    imageCarousel.SelectedIndex = 1;
                else
                    imageCarousel.SelectedIndex--;
            };

            next.Click += (s, e) =>
            {
                if (imageCarousel.SelectedIndex == 1)
                    imageCarousel.SelectedIndex = 0;
                else
                    imageCarousel.SelectedIndex++;
            };

            return new TabItem
            {
                Header = "Images",
                Content = new ScrollViewer
                {
                    Content = new StackPanel
                    {
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Orientation = Orientation.Vertical,
                        VerticalAlignment = VerticalAlignment.Top,
                        Gap = 4,
                        Margin = new Thickness(10),
                        Children = new Controls
                        {
                            new TextBlock
                            {
                                Text = "Carousel",
                                FontWeight = FontWeight.Medium,
                                FontSize = 20,
                                Foreground = Brush.Parse("#212121"),
                            },
                            new TextBlock
                            {
                                Text = "An items control that displays its items as pages that fill the controls.",
                                FontSize = 13,
                                Foreground = Brush.Parse("#727272"),
                                Margin = new Thickness(0, 0, 0, 10)
                            },
                            new StackPanel
                            {
                                Name = "carouselVisual",
                                Orientation = Orientation.Horizontal,
                                Gap = 4,
                                Children = new Controls
                                {
                                    prev,
                                    imageCarousel,
                                    next
                                }
                            }
                        }
                    }
                }
            };
        }