mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-11 11:46:36 +08:00
feat: add button spinner infra.
This commit is contained in:
50
demo/Semi.Avalonia.Demo/Pages/ButtonSpinnerDemo.axaml.cs
Normal file
50
demo/Semi.Avalonia.Demo/Pages/ButtonSpinnerDemo.axaml.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Pages;
|
||||
|
||||
public partial class ButtonSpinnerDemo : UserControl
|
||||
{
|
||||
public ButtonSpinnerDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void OnSpin(object sender, SpinEventArgs e)
|
||||
{
|
||||
var spinner = (ButtonSpinner)sender;
|
||||
|
||||
if (spinner.Content is TextBlock txtBox)
|
||||
{
|
||||
int value = Array.IndexOf(_mountains, txtBox.Text);
|
||||
if (e.Direction == SpinDirection.Increase)
|
||||
value++;
|
||||
else
|
||||
value--;
|
||||
|
||||
if (value < 0)
|
||||
value = _mountains.Length - 1;
|
||||
else if (value >= _mountains.Length)
|
||||
value = 0;
|
||||
|
||||
txtBox.Text = _mountains[value];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private readonly string[] _mountains = new[]
|
||||
{
|
||||
"Everest",
|
||||
"K2 (Mount Godwin Austen)",
|
||||
"Kangchenjunga",
|
||||
"Lhotse",
|
||||
"Makalu",
|
||||
"Cho Oyu",
|
||||
"Dhaulagiri",
|
||||
"Manaslu",
|
||||
"Nanga Parbat",
|
||||
"Annapurna"
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user