本記事の概要
この記事では Stepper の基本使用方法について説明します。
Stepper は [-] と[+] のボタンがあり、押すことで値を増減させることができます。
公式サイト情報はコチラを参照してください。
Stepper の基本使用方法
XAML で Stepper を作成するには <Stepper> を使用します。
Slider の稼働範囲の最小値は Minimum プロパティで、最大値は Maximum プロパティで取得/設定をすることができます。また、現在値は Value プロパティで取得/設定をすることができます。
XAML の例
以下の例では、Stepper を配置し、稼働範囲の最小値は 0、最大値は 10 に設定し、現在値を 5 に設定する例です。
XAML の例
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppSample.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Slider Minimum="0" Maximum="10"
Value="5"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
C# の例
以下は 先ほどのXAML の例を コードビハインドで行う例です。
C# の例
public MainPage()
{
InitializeComponent();
myStepper.Minimum = 0;
myStepper.Maximum = 10;
myStepper.Value = 5;
}
XAML の例
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppSample.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Stepper x:Name="myStepper"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
.NET MAUI Tips
本サイトでまとめている .NET MAUI Tips の一覧はこちらから確認できます。
Please follow and like us:


コメント