【发布时间】:2020-10-11 04:50:15
【问题描述】:
我有一个ListView 和一个ItemTemplate。对于我的ItemSource 中的每个项目,我想遍历项目中的一个属性并在我的ViewCell 中创建一个部分。
所以每个项目都是Download:
public class Download
{
public string Title { get; set; }
public IEnumerable<SectionDownload> SectionDownloads { get; set; }
}
SectionDownload 看起来像这样:
public class SectionDownload
{
public long TotalBytes { get; set; }
public long DownloadedBytes { get; set; }
public int PercentDownloaded { get => (int)((DownloadedBytes / TotalBytes) * 100); }
}
还有我的ListView,其中Downloads 在我的ViewModel 中是ObservableCollection<Download>:
<ListView x:Name="DownloadsListView" SelectionMode="None" ItemsSource="{Binding Downloads}">
<ListView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10">
<Label Text="{Binding Title}"
d:Text="{Binding .}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<!-- Here I would like each SectionDownload to display the percentage downloaded -->
</StackLayout>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
标签: c# xamarin mvvm xamarin.forms data-binding