【发布时间】:2020-06-08 23:59:05
【问题描述】:
我想知道如何在我的 ListView - ViewCell on item tapped 事件中切换当前复选框。
<ListView x:Name="listViewCities"
ItemSelected="ListViewCities_ItemSelected"
ItemTapped="ListViewCities_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<CheckBox x:Name="chkSelectedCity" />
<Label Text="{Binding Name}"
FontSize="Medium"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是我的物品点击事件。
private void ListViewCities_ItemTapped(object sender, ItemTappedEventArgs e)
{
//Here i want to toggle the current check box as true
//something like chkSelectedCity.checked = true;
}
【问题讨论】:
-
您需要将复选框绑定到模型上的属性,然后在点击时切换该属性
-
实际上我是 xamarin 表单的初学者。如果您发布示例或示例链接,将会很有帮助。
标签: checkbox xamarin.forms toggle code-behind