2012-03-23 8 views
1

ありがとうございます..wp7でダウンロードした画像を知るには?

私はいくつかのイメージをサーバーから自分のwp7アプリケーションにダウンロードしています。そのために私は次のコードを使用しています。

ObservableCollection<BitmapImage> biList; 
int currentItem; 

private void DownloadImages(string[] imageUriList) 
{ 
    biList = new ObservableCollection<BitmapImage>(); 
    BitmapImage bi; 

    for (int i = 0; i < imageUriList.Length; i++) 
    { 
     bi = new BitmapImage(); 
     biList.Add(bi); 
     bi.UriSource = new Uri(imageUriList[i], UriKind.Absolute); 
     biList[i] = bi; 
    } 
} 

はその後、私は私のWindows Phoneアプリケーションで <Image />コントロールにこれらの画像を一枚ずつを示しています。 「次へ」または「前」ボタンをクリックすると表示画像

private void ShowImages() 
{ 
    imgImage.Source = biList[0]; 
    currentItem = 1; 
} 

や画像のため、私は次のコードを使用してい

<Image x:Name="imgImage" /> 

が変更されています。

private void btnNext_Click(object sender, RoutedEventArgs e) 
{ 
    if(currentItem < biList.Count) 
    { 
     imgImage.Source = biList[currentItem]; 
     currentItem += 1; 
    } 
} 

private void btnPrevious_Click(object sender, RoutedEventArgs e) 
{ 
    if(currentItem > 1) 
    { 
     imgImage.Source = biList[currentItem-2]; 
     currentItem -= 1; 
    } 
} 

これらの画像を表示しようとすると、しばらくすると一部の画像が表示されます。

画像が完全にダウンロードされるようにするにはどうすればよいですか?

+0

は、私はいくつかの 'DownloadStringCompleted'イベントがあるだろうと思います。 –

答えて

3

あなたは、画像をダウンロードするためにWebクライアントを使用することができますし、それが正常にダウンロードされた後、あなたは以下のようにイベントハンドラにコードを追加することができます。

private void GetImage() 
{ 
    WebClient client = new WebClient(); 
    client.OpenReadAsync(new Uri("http://website.com/image.jpg")); 
    client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); 
} 

void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
{ 
    //Image has been downloaded 
    //Do something 
} 
関連する問題