mirror of
https://gitee.com/chinware/atomui.git
synced 2024-12-02 11:57:42 +08:00
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using Avalonia.Controls;
|
|
|
|
namespace AtomUI.Demo.Desktop.ShowCase;
|
|
|
|
public partial class ButtonSpinnerShowCase : UserControl
|
|
{
|
|
public ButtonSpinnerShowCase()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void HandleSpin(object sender, SpinEventArgs e)
|
|
{
|
|
var spinner = (ButtonSpinner)sender;
|
|
|
|
if (spinner.Content is TextBlock textBlock)
|
|
{
|
|
var value = Array.IndexOf(_spinnerItems, textBlock.Text);
|
|
if (e.Direction == SpinDirection.Increase)
|
|
{
|
|
value++;
|
|
}
|
|
else
|
|
{
|
|
value--;
|
|
}
|
|
|
|
if (value < 0)
|
|
{
|
|
value = _spinnerItems.Length - 1;
|
|
}
|
|
else if (value >= _spinnerItems.Length)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
textBlock.Text = _spinnerItems[value];
|
|
}
|
|
}
|
|
|
|
private readonly string[] _spinnerItems =
|
|
{
|
|
"床前明月光",
|
|
"疑是地上霜",
|
|
"举头望明月",
|
|
"低头思故乡"
|
|
};
|
|
} |