本記事の概要
Stepper の [-][+]ボタンの増減量は既定値で1に設定されています。
この記事では Stepper 増減値を変更する方法について説明します。
公式サイト情報はコチラを参照してください。
増減値を変更する
Stepper の増減値は Increment プロパティで変更することができます。既定値は1です。
XAML の例
以下の例では、Stepper を配置し、稼働範囲の最小値を 0、最大値を 100 に設定し、現在値を 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">
<Stepper Minimum="0" Maximum="100"
Value="10"
Increment="5"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
C# の例
以下は 先ほどのXAML の例を コードビハインドで行う例です。
C# の例
public MainPage()
{
InitializeComponent();
myStepper.Minimum = 0;
myStepper.Maximum = 100;
myStepper.Value = 10;
myStepper.Increment = 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:



コメント