2013-05-15 47 views
0

我有一個Flickr上的圖像的URI列表。我在Windows phone Toolkit中使用手勢來顯示圖像並處理輕彈事件。由於圖片在網絡上,源代碼設置正常,但進度條在輕拂時立即摺疊(隱藏),因爲它已經設置了圖像和手機的來源,仍然需要下載並顯示它。如何在Windows Phone 8中顯示來自網絡的圖片的進度條?

我希望顯示進度條,直到圖像完全可見。 (使用Web客戶端有用嗎?)

下面是一個簡單的視頻顯示到底發生了什麼。不介意這些照片,我只是拿起了第一個出來的東西。

Video Link

的代碼如下:

private void GestureListener_Flick(object sender, FlickGestureEventArgs e) 
       { 
        if (((e.Angle <= 180 && e.Angle >= 135) || (e.Angle < 225 && e.Angle > 180)) && e.Direction.ToString().Equals("Horizontal")) 
        { 
         progess_bar.Visibility=Visibility.Visible; 
         if(index<photoslist.Count-1) 
         index++; 
         image.Source = new BitmapImage(new Uri(photoslist[index].LargeUrl , UriKind.Absolute)); 
         progess_bar.Visibility = Visibility.Collapsed; 
        } 
        else if (((e.Angle <= 45 && e.Angle >= 0) || (e.Angle < 360 && e.Angle >= 315)) && e.Direction.ToString().Equals("Horizontal")) 
        { 
         progess_bar.Visibility = Visibility.Visible; 
         if (index > 0) 
          index--; 
         else 
          index = 0; 
         image.Source = new BitmapImage(new Uri(photoslist[index].LargeUrl, UriKind.Absolute)); 
         progess_bar.Visibility = Visibility.Collapsed; 
        } 
       } 

回答

0

設置在圖像源屬性確實塊正在運行的線程,直至下載完成這樣的代碼將繼續執行,而你的進度條會立即被無形。

如果要提供真正的進度條功能,那麼你就必須手動下載圖像和更新基於進度的進度條。但是,圖像通常不是大文件。您最好展示某種加載動畫,直到圖像下載完成。

+0

所以我基本上會等待一個webclient的downloadasync函數,並根據它顯示下載進度。我確實想到了這一點,但會比我想要的更多地進行編碼。 必須有一個更簡單的方法 –

+0

如果你想捕獲下載進度,你必須編寫代碼,否則沒有其他方式獲得通知。 –

+0

是的,我做了更多的研究,等待異步電話是取得進展的方式 感謝您的回覆 –

0

對於那些有興趣我有粗糙的代碼解決方案,低於該作品。 (請注意,它沒有優化,你可以在它上面工作)

private void GestureListener_Flick(object sender, FlickGestureEventArgs e) 
     { 
      if (((e.Angle <= 180 && e.Angle >= 135) || (e.Angle < 225 && e.Angle > 180)) && e.Direction.ToString().Equals("Horizontal")) 
      { 
       if (index < photoslist.Count - 1) 
       { 
        index++; 
        downloadImage(); 
       } 
       //image_big.Source = new BitmapImage(new Uri(photoslist[index].LargeUrl , UriKind.Absolute)); 
      } 
      else if (((e.Angle <= 45 && e.Angle >= 0) || (e.Angle < 360 && e.Angle >= 315)) && e.Direction.ToString().Equals("Horizontal")) 
      { 
       if (index > 0) 
       { 
        index--; 
        downloadImage(); 
       } 
       //image_big.Source = new BitmapImage(new Uri(photoslist[index].LargeUrl, UriKind.Absolute)); 

      } 
     } 

     private void downloadImage() 
     { 
      progess_bar.Visibility = Visibility.Visible; 
      WebClient wc = new WebClient(); 
      wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted); 
      wc.OpenReadAsync(new Uri(photoslist[index].LargeUrl, UriKind.Absolute), wc); 
     } 

     private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
     { 
      if (e.Error == null && !e.Cancelled) 
      { 
       try 
       { 
        BitmapImage image = new BitmapImage(); 
        image.SetSource(e.Result); 
        image_big.Source = image; 
        progess_bar.Visibility = Visibility.Collapsed; 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show("Cannot get the feed right now.Please try later."); 
       } 
      } 
     } 
    } 
相關問題