none
Stackpanel image download

    Question

  • I have a stackpanel inside a ScrollView:

    <ScrollViewer Grid.Row="0">
                <StackPanel x:Name="stackpanel" Orientation="Vertical" />
            </ScrollViewer>


    Then I load images I get from the internet. I download the images and save them as so:

    Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    
                try {
                    StorageFile file = await localFolder.CreateFileAsync("image_" + id + ".jpg", CreationCollisionOption.ReplaceExisting);
                    await FileIO.WriteBytesAsync(file, responseBytes);
                } catch (System.Exception)
                {
    
                }

    Is there another way to do this or is the most efficient?

    I have a foreach loop to download the image and then display it. What I want to do it generate progress rings, then start the image download for each image. I know how to make progress rings and adding them, the issue is then removing them and putting an image in it's place. Here is what I currently have:

                foreach (var item in array)
                {
                     var tmp = new Image();
                    if (await ApplicationData.Current.LocalFolder.TryGetItemAsync("image_" + item.ToString() + ".jpg") != null)
                    {
                        Debug.WriteLine("File exists");
                    }
                    else
                    {
                        Debug.WriteLine("File doesn't exist");
                        await getImage(int.Parse(item.ToString()));
                    }
    
                    //await getImage(int.Parse(item.ToString()));
                    if (int.Parse(item.ToString()) == 1)
                    {
                        tmp.Margin = new Thickness(0, 0, 0, 50);
                    } else
                    {
                        tmp.Margin = new Thickness(0, 50, 0, 50);
                    }
                    tmp.Name = item.ToString();
                    tmp.DoubleTapped += Tmp_DoubleTapped;
                    tmp.PointerPressed += Tmp_PointerPressed;
                    tmp.Source = new BitmapImage(new Uri("ms-appdata:///local/image_" + item.ToString() + ".jpg", UriKind.Absolute));
                    stackpanel.Children.Add(tmp);
                }

    This just displays a blank image until the image is downloaded and saved, and introduces a little caching. Any ideas?


    Saturday, December 12, 2015 8:56 PM