本文介绍了ListView Itemsource不显示对象Xamarin表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此列表视图与我不合作.我试图显示一些服务时间.请看下面的截图1.我得到了一份物品清单
This list view is just not cooperating with me. I'm trying to display some hours that comes from service.Please see the following screenshot1. I got a list of Items
- 在这些项目中,我需要时间列表
- Inside those Items, I need Time list
3.Xaml看起来像这样-注意=我尝试了{Binding Time}
3.Xaml looks like this - Note = I tried {Binding Time}
<ListView x:Name="HoursList" ItemsSource="{Binding PIEItems}"
CachingStrategy ="RecycleElement"
Grid.Row="2"
Grid.ColumnSpan="3"
HasUnevenRows="True"
SeparatorVisibility="Default"
SeparatorColor="Navy">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Times}"></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
3.View模型
ObservableCollection<DaysFormatting> _pieitems;
public ObservableCollection<DaysFormatting> PIEItems
{
get
{
return _pieitems;
}
set
{
if (_pieitems != value)
{
_pieitems = value;
PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(nameof(PIEItems)));
}
}
}
//on方法=>编辑
public void GetTimer()
{
if (a == c)
{
List<AvailableHrs> lsthrs = await data.GeteTimes(c, serviceId);
ChosenDates.Time = new List<string>();
foreach (var hr in lsthrs)
{
ChosenDates.horas = hr.time;
Debug.WriteLine("to be ...." + ChosenDates.horas);
ChosenDates.Time.Add(hr.time);
Debug.WriteLine("to be in binding" + ChosenDates.Time);
}
}
AvailableDates.Add(ChosenDates);
}
PIEItems = new ObservableCollection<DaysFormatting>(AvailableDates);
}
推荐答案
由于您试图访问PIEItems内部的Times属性,因此需要像这样绑定列表视图:
since you're trying to access the property Times inside PIEItems, you need to bind your list view like this:
<ListView x:Name="HoursList" ItemsSource="{Binding PIEItems.Times}">
并访问其道具,如下所示:
And access to its props like this:
<ListView x:Name="HoursList" ItemsSource="{Binding PIEItems.Times}"
CachingStrategy ="RecycleElement"
Grid.Row="2"
Grid.ColumnSpan="3"
HasUnevenRows="True"
SeparatorVisibility="Default"
SeparatorColor="Navy">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Capacity}"></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
希望它对您有用:)
这篇关于ListView Itemsource不显示对象Xamarin表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!