2024-08-17 20:54:57 +08:00
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
|
|
|
|
namespace AtomUI.Demo.Desktop.ShowCase;
|
|
|
|
|
|
|
|
|
|
public partial class ButtonSpinnerShowCase : UserControl
|
|
|
|
|
{
|
2024-09-10 12:46:41 +08:00
|
|
|
|
public ButtonSpinnerShowCase()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2024-08-18 15:39:00 +08:00
|
|
|
|
|
2024-09-10 12:46:41 +08:00
|
|
|
|
public void HandleSpin(object sender, SpinEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var spinner = (ButtonSpinner)sender;
|
2024-08-18 15:39:00 +08:00
|
|
|
|
|
2024-09-10 12:46:41 +08:00
|
|
|
|
if (spinner.Content is TextBlock textBlock)
|
|
|
|
|
{
|
|
|
|
|
var value = Array.IndexOf(_spinnerItems, textBlock.Text);
|
|
|
|
|
if (e.Direction == SpinDirection.Increase)
|
|
|
|
|
{
|
|
|
|
|
value++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
value--;
|
|
|
|
|
}
|
2024-08-18 15:39:00 +08:00
|
|
|
|
|
2024-09-10 12:46:41 +08:00
|
|
|
|
if (value < 0)
|
|
|
|
|
{
|
|
|
|
|
value = _spinnerItems.Length - 1;
|
|
|
|
|
}
|
|
|
|
|
else if (value >= _spinnerItems.Length)
|
|
|
|
|
{
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textBlock.Text = _spinnerItems[value];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly string[] _spinnerItems =
|
|
|
|
|
{
|
|
|
|
|
"床前明月光",
|
|
|
|
|
"疑是地上霜",
|
|
|
|
|
"举头望明月",
|
|
|
|
|
"低头思故乡"
|
|
|
|
|
};
|
2024-08-17 20:54:57 +08:00
|
|
|
|
}
|