简体   繁体   中英

UWP FlipView Images from URI (Web)

Actually, i have a list with image URIs. Inside a foreach-loop i create Image objects from these URIs like this:

foreach (Uri imageUri in uriList)
{
    BitmapImage bmi = new BitmapImage(new Uri(imageUri));
    Image image = new Image();
    image.source = bmi;

    flipView.Items.Add(image);
}

Now the problem is, if there are many Images (100-200), then the RAM usage is very high, when swiping fast through the FlipView. What i have seen also is, that every image, will be "cached" or something, so if i go back in the FlipView, no more internet traffic will be generated.

So my question is, is this the right way to do that, ore are there better ways to get a "Image Gallery" from Web Images?

Best Regards

The flip view doesn't intended to be used to display large amount of items. You should use horizontal ListView instead.

First, you need to modify the style of the ListView to change HorizontalSnapPointsType property to MandatorySingle (so the image can be snap to correct position like the flip view). The cell's width should be equal to flipview's old width to ensure that

From MSDN , FlipView works best for a collection of that doesn't exceed 25 items (images).

The best thing you can do is to add `DataVirtualization to your FlipView, for example by doing :

<FlipView>
    <FlipView.ItemsPanel>
      <ItemsPanelTemplate>
        <VirtualizingStackPanel Orientation="Horizontal"/>
      </ItemsPanelTemplate>
    </FlipView.ItemsPanel>
</FlipView>

Concerning your images being "cached", that's normal, BitmapeImages cache your images by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM