本記事の概要
この記事では CheckBox を無効化する方法について説明します。
公式サイト情報はコチラを参照してください。
CheckBox の無効化
CheckBox を無効化するには IsEnabled プロパティに False を設定します。
XAML の例
以下の例では、XAML で CheckBox を、チェック状態を Label に表示する例です。
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"> <StackLayout Orientation="Horizontal"> <CheckBox IsChecked="True" IsEnabled="False"/> <Label Text="無効化" FontSize="Medium" /> </StackLayout> </VerticalStackLayout> </ScrollView> </ContentPage>
C# の例
以下は 先ほどのXAML の例を コードビハインドで行う例です。
public MainPage() { InitializeComponent(); myCheckBox.IsEnabled = false; }
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"> <StackLayout Orientation="Horizontal"> <CheckBox x:Name="myCheckBox" IsChecked="True"/> <Label Text="無効化" FontSize="Medium" /> </StackLayout> </VerticalStackLayout> </ScrollView> </ContentPage>
.NET MAUI Tips
本サイトでまとめている .NET MAUI Tips の一覧はこちらから確認できます。
Please follow and like us:
コメント