CarouselGettingStartedPage.xaml.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. namespace ControlCatalog.Pages
  4. {
  5. public partial class CarouselGettingStartedPage : UserControl
  6. {
  7. public CarouselGettingStartedPage()
  8. {
  9. InitializeComponent();
  10. PreviousButton.Click += OnPrevious;
  11. NextButton.Click += OnNext;
  12. DemoCarousel.SelectionChanged += OnSelectionChanged;
  13. }
  14. private void OnPrevious(object? sender, RoutedEventArgs e)
  15. {
  16. DemoCarousel.Previous();
  17. UpdateStatus();
  18. }
  19. private void OnNext(object? sender, RoutedEventArgs e)
  20. {
  21. DemoCarousel.Next();
  22. UpdateStatus();
  23. }
  24. private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
  25. {
  26. UpdateStatus();
  27. }
  28. private void UpdateStatus()
  29. {
  30. var index = DemoCarousel.SelectedIndex + 1;
  31. var count = DemoCarousel.ItemCount;
  32. StatusText.Text = $"Item: {index} / {count}";
  33. }
  34. }
  35. }