当测试具有100000个项目的简单ListView时,ListView开始与其下方的项目重叠。有办法解决吗?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="500"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,10,10,10" x:Name="pageTitle" Text="Page 1" />
<ListView Grid.Row="1" Grid.Column="1" Margin="10,10,10,10" x:Name="itemListView" ItemsSource="{x:Bind Items}"/>
<TextBlock Grid.Row="2" Grid.Column="1" Margin="10,10,10,10" Text="Bottom Text" />
</Grid>
背后的代码:
private ObservableCollection<string> _items = new ObservableCollection<string>();
public ObservableCollection<string> Items
{
get { return this._items; }
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
FillItems();
}
private void FillItems()
{
for (int i = 0; i < 100000; i++)
{
Items.Add($"Item {i}");
}
}
答案 0 :(得分:0)
同时加载所有元素会导致性能问题。您可以使用增量加载随着滚动条的进度加载元素。通过实现IIncrementalSource
。您可以设置可以携带多少物品
每次视图需要调用GetPagedItemsAsync方法时 显示更多项目。
public async Task<IEnumerable<Person>> GetPagedItemsAsync(int pageIndex, int pageSize)
{
// Gets items from the collection according to pageIndex and pageSize parameters.
var result = (from p in people
select p).Skip(pageIndex * pageSize).Take(pageSize);
return result;
}