1
0

CarouselCustomizationPage.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using Avalonia.Animation;
  3. using Avalonia.Controls;
  4. using Avalonia.Controls.Primitives;
  5. using Avalonia.Interactivity;
  6. namespace ControlCatalog.Pages
  7. {
  8. public partial class CarouselCustomizationPage : UserControl
  9. {
  10. public CarouselCustomizationPage()
  11. {
  12. InitializeComponent();
  13. PreviousButton.Click += (_, _) => DemoCarousel.Previous();
  14. NextButton.Click += (_, _) => DemoCarousel.Next();
  15. OrientationCombo.SelectionChanged += (_, _) => ApplyOrientation();
  16. ViewportSlider.ValueChanged += OnViewportFractionChanged;
  17. }
  18. private void ApplyOrientation()
  19. {
  20. var horizontal = OrientationCombo.SelectedIndex == 0;
  21. var axis = horizontal ? PageSlide.SlideAxis.Horizontal : PageSlide.SlideAxis.Vertical;
  22. DemoCarousel.PageTransition = new PageSlide(TimeSpan.FromSeconds(0.25), axis);
  23. StatusText.Text = $"Orientation: {(horizontal ? "Horizontal" : "Vertical")}";
  24. }
  25. private void OnViewportFractionChanged(object? sender, RangeBaseValueChangedEventArgs e)
  26. {
  27. var value = Math.Round(e.NewValue, 2);
  28. DemoCarousel.ViewportFraction = value;
  29. ViewportLabel.Text = value.ToString("0.00");
  30. ViewportHint.Text = value >= 1d ?
  31. "1.00 shows a single full page." :
  32. $"{1d / value:0.##} pages fit in view. Try 0.80 for peeking.";
  33. }
  34. private void OnWrapSelectionChanged(object? sender, RoutedEventArgs e)
  35. {
  36. DemoCarousel.WrapSelection = WrapSelectionCheck.IsChecked == true;
  37. }
  38. private void OnSwipeEnabledChanged(object? sender, RoutedEventArgs e)
  39. {
  40. DemoCarousel.IsSwipeEnabled = SwipeEnabledCheck.IsChecked == true;
  41. }
  42. }
  43. }