Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows store apps 在VirtualzingStackPanel中检测延迟加载图像的项目可见性_Windows Store Apps_Virtualizingstackpanel - Fatal编程技术网

Windows store apps 在VirtualzingStackPanel中检测延迟加载图像的项目可见性

Windows store apps 在VirtualzingStackPanel中检测延迟加载图像的项目可见性,windows-store-apps,virtualizingstackpanel,Windows Store Apps,Virtualizingstackpanel,以下是我的设想: 我有一个Gridview,显示从网络服务检索到的数据。数据的数量可能相当大。因此,VirtualzingStackPanel用于显示内容。其中一些数据在渲染时可能需要检索图像(延迟加载) 我(非常有限)的理解是,当网格需要数据时,VirtualStackPanel将自动请求数据。如果需要呈现的元素是图像类型,我会发送一个占位符图像并提交一个异步网络调用来检索该图像 但是,我注意到正在接收渲染所有元素的调用,因此发送了大量检索图像的网络调用(尤其是在大多数项目都是图像类型的情况下

以下是我的设想:

我有一个Gridview,显示从网络服务检索到的数据。数据的数量可能相当大。因此,VirtualzingStackPanel用于显示内容。其中一些数据在渲染时可能需要检索图像(延迟加载)

我(非常有限)的理解是,当网格需要数据时,VirtualStackPanel将自动请求数据。如果需要呈现的元素是图像类型,我会发送一个占位符图像并提交一个异步网络调用来检索该图像

但是,我注意到正在接收渲染所有元素的调用,因此发送了大量检索图像的网络调用(尤其是在大多数项目都是图像类型的情况下)

问题:我是否应该在代码(XAML或C#)中为VirtualzingStackPanel配置一些东西,或者应该检测项目是否真的在显示,然后发出网络调用

这是我的XAML

    <GridView
        x:Name="itemGridView"
        AutomationProperties.AutomationId="ItemGridView"
        AutomationProperties.Name="Grouped Items"
        Grid.RowSpan="3"
        Padding="116,137,40,46"
        ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
        VirtualizingStackPanel.VirtualizationMode="Standard"
        ItemTemplateSelector="{StaticResource CellStyleSelector}"
        ItemClick="ItemView_ItemClick"
        IsItemClickEnabled="True"
        SelectionMode="None"
        IsSwipeEnabled="false">

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>                        
                <VirtualizingStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>
下面是下载thumb的异步调用

private async void getThumb()
{
   // Get image and store
   Network network = new Network();

   // Since this is a bound property. this action updates the UI
   this.ThumbImage = await network.getImage(this._rawData[Defs.PATH_KEY], true);

   Debug.WriteLine(this._rawData[Defs.PATH_KEY] + " - Thumb retrieved!");

}

您正在模型中进行延迟加载吗?如果是,那么这就是请求图像的来源。您应该只在请求图像数据属性时启动延迟加载过程(即,如果尚未加载该属性)。是。在调用绑定的图像获取程序时,我确实调用了延迟加载。但是我注意到图像的getter被调用用于所有项目。。。如果您的模型中没有更多的代码,将很难提供更多帮助。有几个地方可能会发生这种情况,但那是最有可能发生的地方。您可以做的一件有帮助的事情是在getter中放置一个断点,然后遍历堆栈跟踪以查看首先调用它的内容。根据您的标准,您可能必须继续阅读前几篇文章,才能找到一篇不应该被调用的文章。@Nate谢谢。我在帖子中添加了额外的代码。这有意义吗?该链接表示分组数据不支持UI虚拟化。。
private async void getThumb()
{
   // Get image and store
   Network network = new Network();

   // Since this is a bound property. this action updates the UI
   this.ThumbImage = await network.getImage(this._rawData[Defs.PATH_KEY], true);

   Debug.WriteLine(this._rawData[Defs.PATH_KEY] + " - Thumb retrieved!");

}