【发布时间】:2019-12-23 07:16:55
【问题描述】:
我有一个 xamarin.forms 应用程序,其中包含一个带有复选框的列表视图。单击按钮后,我可以获得列表视图的复选框选中项目。但是我想要实现的是,当用户单击每个列表项上的复选框时,顶部的标签将显示复选框单击计数。 例如; 20 个中有 11 个被选中。当用户选中或取消选中复选框时,如何实现此复选框选中的计数值?
我的数据模型
public class TimeSheetListData : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public string EmployeeID { get; set; }
public string EndDate { get; set; }
public string SlNo { get; set; }
//Checkbox selection
private bool selected;
public bool Selected
{
get
{
return selected;
}
set
{
if (value != null)
{
selected = value;
NotifyPropertyChanged("Selected");
}
}
}
}
我的 xaml
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical">
// Where Iam trying to show count
<Label x:Name="Count" Text="" FontSize="Small" TextColor="Black" VerticalOptions="Center" >
<ListView x:Name="TimesheetListView" ItemsSource="{Binding} "
HeightRequest="{Binding Path=Height, Source={x:Reference ListLayout}}"
BackgroundColor="Transparent"
CachingStrategy="RecycleElement"
SeparatorVisibility="None"
HasUnevenRows="True"
HorizontalOptions="FillAndExpand"
Margin="11,2,11,2"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Frame ClassId="{Binding EmployeeID}" BorderColor="LightGray" >
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical">
<Label Text="{Binding EndDate}" FontSize="Small" TextColor="Black" VerticalOptions="Center" >
</Label>
<Label Text="{Binding SlNo}" FontSize="Small" TextColor="Black" VerticalOptions="Center" >
</Label>
<CheckBox x:Name="MultiSelectCheckBox" Grid.Column="2" Color="#004d6f" IsChecked="{Binding Selected}" IsVisible="{Binding IsCheckBoxVisible}" HorizontalOptions="End" VerticalOptions="Center"></CheckBox>
</StackLayout>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView
</StackLayout>
感谢任何帮助。
【问题讨论】:
-
这里
ItemsSource="{Binding}的绑定属性是什么?可以用来计数。 -
@AndroDevil 查看我的答案,您可能会遇到当前的问题!!!!
标签: xamarin.forms