所以我正在创建一个正在进行项目自定义排序的面板。这一部分有很好的记录。但是当我有一个包含大量项目的集合时,渲染面板第一次占用了大量时间。所以为了解决这个问题,我的想法是向我的面板添加增量加载。但是在文档中我无法找到任何信息,以便在自定义面板中启用增量加载。有人在定制面板中添加增量加载吗?第二个想法是实现虚拟化,但我找不到任何有关这方面的信息。
public class TilePanel : Panel
{
private const double WidthOfTile = 296;
private const double HeightOfTile = 144;
protected override Size ArrangeOverride(Size finalSize)
{
double x = 0;
double y = 0;
int numberOfColumns = (int)Math.Floor(finalSize.Width / WidthOfTile);
var children = Children;
for (int i = 0; i < Children.Count; i++)
{
var item = Children[i];
x = (i % numberOfColumns) * WidthOfTile;
y = (i / numberOfColumns) * HeightOfTile;
var rect = new Rect(new Point(x, y), new Size(WidthOfTile, HeightOfTile));
item.Arrange(rect);
}
return finalSize;
}
protected override Size MeasureOverride(Size availableSize)
{
double numberOfColumns = Math.Floor(availableSize.Width / WidthOfTile);
double numberOfRows = Math.Ceiling(Children.Count / numberOfColumns);
double width = numberOfColumns * WidthOfTile;
return new Size(width, numberOfRows * HeightOfTile);
}
}
XAML文件:
<GridView
Grid.Column="1"
Margin="0,0,0,0"
IncrementalLoadingThreshold="10"
IncrementalLoadingTrigger="Edge"
ItemsSource="{Binding LoadingCollection}">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<controls1:TilePanel />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<ContentControl
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{Binding}"
ContentTemplateSelector="{StaticResource DeviceTemplateSelector}" />
</DataTemplate>
</GridView.ItemTemplate>
</controls1:VariableGrid>
正如您所见,控件绑定到IncrementalLoadingCollection
deviceViewModels = new ObservableCollection<WidgetViewModel>();
loadingCollection = new IncrementalLoadingCollection<NotifyObservableCollection<WidgetViewModel>, WidgetViewModel>(deviceViewModels, 50);