CarouselMultiItemPage.xaml.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Primitives;
  4. using Avalonia.Interactivity;
  5. namespace ControlCatalog.Pages
  6. {
  7. public partial class CarouselMultiItemPage : UserControl
  8. {
  9. public CarouselMultiItemPage()
  10. {
  11. InitializeComponent();
  12. PreviousButton.Click += (_, _) => DemoCarousel.Previous();
  13. NextButton.Click += (_, _) => DemoCarousel.Next();
  14. DemoCarousel.SelectionChanged += OnSelectionChanged;
  15. }
  16. private void OnViewportFractionChanged(object? sender, RangeBaseValueChangedEventArgs e)
  17. {
  18. if (DemoCarousel is null)
  19. return;
  20. var value = Math.Round(e.NewValue, 2);
  21. DemoCarousel.ViewportFraction = value;
  22. ViewportLabel.Text = value.ToString("0.00");
  23. ViewportHint.Text = value >= 1d ? "1.00 — single full item." : $"~{1d / value:0.#} items visible.";
  24. }
  25. private void OnWrapChanged(object? sender, RoutedEventArgs e)
  26. {
  27. if (DemoCarousel is null)
  28. return;
  29. DemoCarousel.WrapSelection = WrapCheck.IsChecked == true;
  30. }
  31. private void OnSwipeChanged(object? sender, RoutedEventArgs e)
  32. {
  33. if (DemoCarousel is null)
  34. return;
  35. DemoCarousel.IsSwipeEnabled = SwipeCheck.IsChecked == true;
  36. }
  37. private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
  38. {
  39. StatusText.Text = $"Item: {DemoCarousel.SelectedIndex + 1} / {DemoCarousel.ItemCount}";
  40. }
  41. }
  42. }