Exemplo n.º 1
0
 private void InitializeComponent()
 {
     PerspexXamlLoader.Load(this);
     _carousel = this.FindControl<Carousel>("carousel");
     _left = this.FindControl<Button>("left");
     _right = this.FindControl<Button>("right");
 }
Exemplo n.º 2
0
 /// <summary>
 /// The default template for the <see cref="Carousel"/> control.
 /// </summary>
 /// <param name="control">The control being styled.</param>
 /// <returns>The root of the instantiated template.</returns>
 public static Control Template(Carousel control)
 {
     return new CarouselPresenter
     {
         Name = "itemsPresenter",
         MemberSelector = control.MemberSelector,
         [~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty],
         [~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty],
         [~CarouselPresenter.SelectedIndexProperty] = control[~SelectingItemsControl.SelectedIndexProperty],
         [~CarouselPresenter.TransitionProperty] = control[~Carousel.TransitionProperty],
     };
 }
Exemplo n.º 3
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 Perspex.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 Perspex.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 = SolidColorBrush.Parse("#212121"),
                            },
                            new TextBlock
                            {
                                Text = "An items control that displays its items as pages that fill the controls.",
                                FontSize = 13,
                                Foreground = SolidColorBrush.Parse("#727272"),
                                Margin = new Thickness(0, 0, 0, 10)
                            },
                            new StackPanel
                            {
                                Name = "carouselVisual",
                                Orientation = Orientation.Horizontal,
                                Gap = 4,
                                Children = new Controls
                                {
                                    prev,
                                    imageCarousel,
                                    next
                                }
                            }
                        }
                    }
                }
            };
        }