【发布时间】:2022-10-16 21:49:32
【问题描述】:
.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>
【问题讨论】:
-
解决方案有两个部分。 1)编写一个在单击标签时运行的命令。 2) 在该命令的 c# 代码中,以编程方式设置复选框的 IsChecked 属性。研究这两个主题。
-
将手势识别器附加到将切换复选框的标签