此列表视图与我不合作。我试图显示一些服务时间。 请看下面的截图 1.我得到了一份物品清单
3.Xaml看起来像这样-注意=我尝试了{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);
}
答案 0 :(得分:1)
由于您要尝试访问PIEItems内的属性Times,因此需要像这样绑定列表视图:
<ListView x:Name="HoursList" ItemsSource="{Binding PIEItems.Times}">
并访问其道具,如下所示:
<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>
希望它对您有用:)
答案 1 :(得分:0)
您绑定到错误的属性:
更改
<ListView x:Name="HoursList" BindingContext="'PIEItems"
到
<ListView x:Name="HoursList" ItemsSource="{Binding PIEItems}"