gpt4 book ai didi

c# - Xamarin 中项目列表的 ItemTemplate

转载 作者:行者123 更新时间:2023-12-03 10:15:33 24 4
gpt4 key购买 nike

我有一个 ListViewItemTemplate .对于我 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 ,其中 DownloadsObservableCollection<Download>在我的 View 模型中:
<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>

最佳答案

您可以像这样显示部分。

<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" />
<StackLayout BindableLayout.ItemsSource="{Binding SectionDownloads}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<ProgressBar Progress="{Binding PercentDownloaded}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</DataTemplate>
</ListView.ItemTemplate>

PercentDownloaded 的值应该是 0 到 1 范围内的两倍,并且您还必须对 SectionDownload 类实现 INotifyPropertyChange 以实时更新进度。

关于c# - Xamarin 中项目列表的 ItemTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62495570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com