Browse Source

WIP: Trying to repro #2957

And failing...
fixes/2957-carousel-stackoverflow
Steven Kirk 7 years ago
parent
commit
350633c08f
  1. 46
      samples/ControlCatalog/Pages/CarouselPage.xaml
  2. 31
      samples/ControlCatalog/Pages/CarouselPage.xaml.cs

46
samples/ControlCatalog/Pages/CarouselPage.xaml

@ -1,43 +1,11 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ControlCatalog.Pages.CarouselPage">
<StackPanel Orientation="Vertical" Spacing="4">
<TextBlock Classes="h1">Carousel</TextBlock>
<TextBlock Classes="h2">An items control that displays its items as pages that fill the control.</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 16 0 0" Spacing="8">
<Button Name="left" VerticalAlignment="Center" Padding="20">
<Path Data="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" Fill="Black"/>
</Button>
<Carousel Name="carousel">
<Carousel.PageTransition>
<PageSlide Duration="0.25" Orientation="Vertical" />
</Carousel.PageTransition>
<Image Source="/Assets/delicate-arch-896885_640.jpg"/>
<Image Source="/Assets/hirsch-899118_640.jpg"/>
<Image Source="/Assets/maple-leaf-888807_640.jpg"/>
</Carousel>
<Button Name="right" VerticalAlignment="Center" Padding="20">
<Path Data="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" Fill="Black"/>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock VerticalAlignment="Center">Transition</TextBlock>
<ComboBox Name="transition" SelectedIndex="1" VerticalAlignment="Center">
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Slide</ComboBoxItem>
<ComboBoxItem>Crossfade</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock VerticalAlignment="Center">Orientation</TextBlock>
<ComboBox Name="orientation" SelectedIndex="1" VerticalAlignment="Center">
<ComboBoxItem>Horizontal</ComboBoxItem>
<ComboBoxItem>Vertical</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
<DockPanel>
<Button Name="left" DockPanel.Dock="Left" VerticalAlignment="Center">Left</Button>
<Button Name="right" DockPanel.Dock="Right" VerticalAlignment="Center">Right</Button>
<Button Name="add" DockPanel.Dock="Top">Add</Button>
<Carousel Name="carousel" Items="{Binding Items}" SelectedItem="{Binding SelectedItem}">
</Carousel>
</DockPanel>
</UserControl>

31
samples/ControlCatalog/Pages/CarouselPage.xaml.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.ObjectModel;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
@ -10,16 +11,17 @@ namespace ControlCatalog.Pages
private Carousel _carousel;
private Button _left;
private Button _right;
private ComboBox _transition;
private ComboBox _orientation;
private Button _add;
public CarouselPage()
{
this.InitializeComponent();
var vm = new ViewModel();
DataContext = vm;
_left.Click += (s, e) => _carousel.Previous();
_right.Click += (s, e) => _carousel.Next();
_transition.SelectionChanged += TransitionChanged;
_orientation.SelectionChanged += TransitionChanged;
_add.Click += (s, e) => vm.Items.Add("boo");
}
private void InitializeComponent()
@ -28,24 +30,19 @@ namespace ControlCatalog.Pages
_carousel = this.FindControl<Carousel>("carousel");
_left = this.FindControl<Button>("left");
_right = this.FindControl<Button>("right");
_transition = this.FindControl<ComboBox>("transition");
_orientation = this.FindControl<ComboBox>("orientation");
_add = this.FindControl<Button>("add");
}
private void TransitionChanged(object sender, SelectionChangedEventArgs e)
private class ViewModel
{
switch (_transition.SelectedIndex)
public ViewModel()
{
case 0:
_carousel.PageTransition = null;
break;
case 1:
_carousel.PageTransition = new PageSlide(TimeSpan.FromSeconds(0.25), _orientation.SelectedIndex == 0 ? PageSlide.SlideAxis.Horizontal : PageSlide.SlideAxis.Vertical);
break;
case 2:
_carousel.PageTransition = new CrossFade(TimeSpan.FromSeconds(0.25));
break;
Items = new ObservableCollection<string> { "foo", "bar", "baz" };
}
public ObservableCollection<string> Items { get; }
public object SelectedItem { get; set; } = "foo";
}
}
}

Loading…
Cancel
Save