我有10000个对象(需要大量处理)才能加载到我的UWP应用上的GridView。 (查看带有红色突出显示区域的图像。)
首先,我需要从DB获取所有10000条记录,然后逐步处理每个对象,然后将其加载到视图中,同时保持UI响应。
目前一个问题是需要应用程序只需要一行水平显示数据,所以我使用了GridView。这是XAML。
<ScrollViewer Grid.Column="1" Grid.Row="1" HorizontalScrollBarVisibility="Auto" HorizontalScrollMode="Auto"
VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<GridView x:Name="MeetingGridView" ItemsSource="{Binding MeetingList}" Tag="{Binding MeetingList}"
ItemContainerStyle="{StaticResource GridViewItemStyle}" SelectionChanged="MeetingGridViewSelectionChanged"
ItemTemplate="{StaticResource MeetingBoxDataTemplate}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="1"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</ScrollViewer>
我已经实现了ISupportIncrementalLoading,但由于我设计XAML的方式,它在滚动时效果不佳。它不是逐步加载数据,而是将所有内容加载到视图中。因此,在处理完所有内容并加载到视图后,GridView无响应。
这是增量加载代码。
public class ItemsToShow : ObservableCollection<MeetingModel>, ISupportIncrementalLoading
{
public int lastItem = 0;
public bool HasMoreItems
{
get
{
if (_globalDisplayMeetings == null || itemsToSkip == _globalDisplayMeetings.Count || itemsToSkip > _globalDisplayMeetings.Count)
{
return false;
}
else
{
return true;
}
}
}
List<MeetingModel> items = new List<MeetingModel>();
int itemsToSkip = 0;
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
if (itemsToSkip > _globalDisplayMeetings.Count()) { }
ProgressBar progressBar = ((Window.Current.Content as Frame).Content as MeetingsPage).PgbPage;
CoreDispatcher coreDispatcher = Window.Current.Dispatcher;
return Task.Run<LoadMoreItemsResult>(async () =>
{
await coreDispatcher.RunAsync(CoreDispatcherPriority.Low,
() =>
{
progressBar.IsIndeterminate = true;
progressBar.Visibility = Visibility.Visible;
});
items = _globalDisplayMeetings.Skip(itemsToSkip).Take((int)count).ToList();
itemsToSkip = itemsToSkip + (int)count;
await coreDispatcher.RunAsync(CoreDispatcherPriority.Low,
() =>
{
foreach (MeetingModel item in items)
{
this.Add(item);
}
progressBar.Visibility = Visibility.Collapsed;
progressBar.IsIndeterminate = false;
});
return new LoadMoreItemsResult() { Count = count };
}).AsAsyncOperation<LoadMoreItemsResult>();
}
}
请让我知道如何解决这个问题。我需要的行为与Android recyclerview相同。 一切都会有所帮助。感谢。