.NET MAUI 中是否有辦法在單擊旁邊的標簽時切換復選框的狀態?舉個例子:
<?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="MyApp.Views.Test"
Title="Test">
<HorizontalStackLayout>
<CheckBox />
<Label Text="Check this box" VerticalOptions="Center" />
</HorizontalStackLayout>
</ContentPage>
uj5u.com熱心網友回復:
那么基本上你需要做這樣的事情:
<ContentView
Padding="10,20">
<ContentView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SomeThingTappedCommand}" />
</ContentView.GestureRecognizers>
<StackLayout Orientation="Horizontal">
<Label
HorizontalOptions="StartAndExpand"
InputTransparent="True"
Text="Some Title"
VerticalTextAlignment="Center" />
<controls:ExtendedCheckBox
InputTransparent="True"
IsChecked="{Binding IsChecked}"
VerticalOptions="Center"
Color="{DynamicResource PrimaryColor}" />
</StackLayout>
</pan:PancakeView>
然后在你的虛擬機中,你需要做的就是:
SomeThingTappedCommand = new Command(() => IsChecked = !IsChecked);
其中 IsChecked 是應通報財產:
private bool isChecked;
public bool IsChecked
{
get => isChecked;
set => SetProperty(ref isChecked, value);
}
祝你好運
uj5u.com熱心網友回復:
你可以像這樣使用它,一個標簽和一個復選框。
為 CheckBox 命名。
<Label
Text="Check this box"
FontSize="32"
HorizontalOptions="Center" >
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"
NumberOfTapsRequired="1" />
</Label.GestureRecognizers>
</Label>
<CheckBox x:Name="StackO" />
然后對于標簽水龍頭
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
if (StackO.IsChecked )
StackO.IsChecked = false;
else
StackO.IsChecked = true;
}
uj5u.com熱心網友回復:
在 xamarin 檔案中:
<StackLayout Orientation="Horizontal">
<CheckBox x:Name="myCheckBox"
IsChecked="{Binding IsChecked,Mode=TwoWay}">
</CheckBox>
<Label VerticalTextAlignment="Center" Text="Test">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="Clicked"/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
在后面的代碼中:
private void Clicked(object sender, EventArgs e)
{
myCheckBox.IsChecked = !myCheckBox.IsChecked;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512491.html
標籤:C#。网xml毛伊岛
