【发布时间】:2020-04-14 09:08:14
【问题描述】:
我有一个带有 Label 和 Checkbox
的 ListView我想实现一个按钮列表器,它将从我的 ListView
中获取所有选中的项目这是 ListView
<ListView ItemsSource="{Binding OCParticipantsTable}"
HasUnevenRows="True"
x:Name="dsfdf">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding FirstName_}"/>
<CheckBox/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是 ItemsSource 属性:
private ObservableCollection<ParticipantsTable> _OCParticipantsTable =
new ObservableCollection<ParticipantsTable>();
public ObservableCollection<ParticipantsTable> OCParticipantsTable
{
get { return _OCParticipantsTable; }
set
{
if (_OCParticipantsTable != value)
{
_OCParticipantsTable = value;
OnPropertyChanged("ListOfItems");
}
}
}
如何实现一个按钮列表器,它将从我的 ListView 中获取所有选中的项目?
类似的东西:
foreach (var pt in dsfdf.ItemsSource)
{
if (pt.CheckBox.IsChecked)
{
// do something...
}
}
【问题讨论】:
-
使用绑定。将复选框绑定到 VM 中的属性,然后只需检查该属性即可获取所选项目。
标签: listview checkbox xamarin.forms