本記事の概要
この記事では Editor に入力可能な最大文字数を設定する方法について説明をします。
公式サイト情報はコチラを参照してください。
最大入力可能文字数を設定する
Editor のテキスト入力欄は、MaxLength プロパティ を使用して、最大入力可能文字数を設定することができます。10を設定すると最大で10文字まで入力できるように制限できます(半角、全角を問わず最大10文字となります)。
XAML の例
XAML で Editor に最大入力文字数を設定する例を以下に示します。
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">
<Editor Text="Hello .NET MAUI" MaxLength="10" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
C# の例
以下は 先ほどのXAML の例を コードビハインドで行う例です。
C# の例
public MainPage()
{
InitializeComponent();
myEditor1.MaxLength = 10;
}
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">
<Editor x:Name="myEditor1" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
.NET MAUI Tips
本サイトでまとめている .NET MAUI Tips の一覧はこちらから確認できます。
Please follow and like us:


コメント