1
votes

XAML:

    <Grid x:Name="LayoutRoot" VerticalAlignment="Top">
      <ScrollViewer x:Name="ScrollViewer1" Margin="0,0,0,0">
          <StackPanel x:Name="myStackPanel"/>
      </ScrollViewer>
    </Grid>

C#:

    Image[] image2 = new Image[30];

                for (int n = 1; n <= 29; n++)
                {
                    image2[n] = new Image();
                    BitmapImage bitmapa = downloadBitmap(n);
                    image2[n].Source = bitmapa;
                    myStackPanel.Children.Add(image2[n]);
                }

I'm downloading BitmapImage from IsolatedSotrage -> downloadBitmap(n).

When I start the app I have a black image in my phone becouse photos are not visible(why?!), but when I lock the phone and unlock I have all the pictures, everything is ok.

When I remove ScrollViewer i don't have any problem.

Why this is happening? Please help me.

1
Dispatcher.BeginInvoke(() => { image2[n].Source = bitmapa; myStackPanel.Children.Add(image2[n]); }); } An exception of type 'System.NullReferenceException' occurred in MCD.DLL but was not handled in user code If there is a handler for this exception, the program may be safely continued. - lukas
private void SetImage(Image img, BitmapImage bitmapa) { Dispatcher.BeginInvoke(()=> img.Source = bitmapa; myStackPanel.Children.Add(img);} }SetImage(image2[n], bitmapa); - Shashi
Problem is in index n to get element in Dispatcher. So do above solution - Shashi
ok, now your solution works, but I still have the same problem - I have a black image in my phone becouse photos are not visible, but when I lock the phone and unlock (or hold the arrow back in phone) I have all the pictures, everything is ok. - lukas
try to use GRID, to hold picturs - codeSetter

1 Answers

0
votes

Dipak - I used the Grid - I hold each picture in a separate Grid:

                Image[] image2 = new Image[30];
                for (int n = 1; n <= 29; n++)
                {
                    Grid myGrid = new Grid();
                    Image2[n] = new Image();
                    aktualizacja2 bitmapa = new aktualizacja2(n, path);
                    Image2[n].Source = bitmapa.getBitmap();

                    myGrid.Children.Add(Image2[n]);
                    myStackPanel.Children.Add(myGrid);
                }

it works, but loading images takes much longer...