ButtonSpinnerPage.xaml.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using Avalonia.Controls;
  3. namespace ControlCatalog.Pages
  4. {
  5. public partial class ButtonSpinnerPage : UserControl
  6. {
  7. public ButtonSpinnerPage()
  8. {
  9. InitializeComponent();
  10. }
  11. public void OnSpin(object sender, SpinEventArgs e)
  12. {
  13. var spinner = (ButtonSpinner)sender;
  14. if (spinner.Content is TextBlock txtBox)
  15. {
  16. int value = Array.IndexOf(_mountains, txtBox.Text);
  17. if (e.Direction == SpinDirection.Increase)
  18. value++;
  19. else
  20. value--;
  21. if (value < 0)
  22. value = _mountains.Length - 1;
  23. else if (value >= _mountains.Length)
  24. value = 0;
  25. txtBox.Text = _mountains[value];
  26. }
  27. }
  28. private readonly string[] _mountains = new[]
  29. {
  30. "Everest",
  31. "K2 (Mount Godwin Austen)",
  32. "Kangchenjunga",
  33. "Lhotse",
  34. "Makalu",
  35. "Cho Oyu",
  36. "Dhaulagiri",
  37. "Manaslu",
  38. "Nanga Parbat",
  39. "Annapurna"
  40. };
  41. }
  42. }