csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
using System;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
namespace ControlCatalog.Pages
|
|
{
|
|
public class ButtonSpinnerPage : UserControl
|
|
{
|
|
public ButtonSpinnerPage()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
private void OnSpin(object sender, SpinEventArgs e)
|
|
{
|
|
var spinner = (ButtonSpinner)sender;
|
|
var txtBox = (TextBlock)spinner.Content;
|
|
|
|
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"
|
|
};
|
|
}
|
|
}
|
|
|