SetVolumeWindow.axaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Primitives;
  3. namespace SlamCross.Views;
  4. public partial class SetVolumeWindow : Window
  5. {
  6. public int Volume { get; private set; } = -1;
  7. private bool _updating;
  8. public SetVolumeWindow() => InitializeComponent();
  9. private void Slider_Changed(object? sender, RangeBaseValueChangedEventArgs e)
  10. {
  11. if (_updating) return;
  12. _updating = true;
  13. if (this.FindControl<TextBox>("VolumeBox") is TextBox box)
  14. box.Text = ((int)e.NewValue).ToString();
  15. _updating = false;
  16. }
  17. private void Box_Changed(object? sender, TextChangedEventArgs e)
  18. {
  19. if (_updating) return;
  20. if (this.FindControl<TextBox>("VolumeBox") is not TextBox box) return;
  21. if (int.TryParse(box.Text, out int v) && v is >= 1 and <= 100)
  22. {
  23. _updating = true;
  24. if (this.FindControl<Slider>("VolumeSlider") is Slider s) s.Value = v;
  25. _updating = false;
  26. }
  27. }
  28. private void OK_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
  29. {
  30. if (this.FindControl<Slider>("VolumeSlider") is Slider s)
  31. Volume = (int)s.Value;
  32. Close();
  33. }
  34. private void Cancel_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
  35. => Close();
  36. }