| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using Avalonia.Controls;
- using Avalonia.Controls.Primitives;
- namespace SlamCross.Views;
- public partial class SetVolumeWindow : Window
- {
- public int Volume { get; private set; } = -1;
- private bool _updating;
- public SetVolumeWindow() => InitializeComponent();
- private void Slider_Changed(object? sender, RangeBaseValueChangedEventArgs e)
- {
- if (_updating) return;
- _updating = true;
- if (this.FindControl<TextBox>("VolumeBox") is TextBox box)
- box.Text = ((int)e.NewValue).ToString();
- _updating = false;
- }
- private void Box_Changed(object? sender, TextChangedEventArgs e)
- {
- if (_updating) return;
- if (this.FindControl<TextBox>("VolumeBox") is not TextBox box) return;
- if (int.TryParse(box.Text, out int v) && v is >= 1 and <= 100)
- {
- _updating = true;
- if (this.FindControl<Slider>("VolumeSlider") is Slider s) s.Value = v;
- _updating = false;
- }
- }
- private void OK_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
- {
- if (this.FindControl<Slider>("VolumeSlider") is Slider s)
- Volume = (int)s.Value;
- Close();
- }
- private void Cancel_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
- => Close();
- }
|