我從Bing獲取圖像以顯示在我的應用程序中。我遵循Bing的指示,我成功地檢索了圖像的URL,但出於某種原因,模擬器不會顯示它們!下面是我有Windows Phone,在異步回調上設置圖像源不起作用?
var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/"));
var accountKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
var imageQuery = bingContainer.Image("porsche", null, null, null, null, null, "Size:Medium");
imageQuery.BeginExecute(new AsyncCallback(this.ImageResultLoadedCallback), imageQuery);
然後,我讓我的圖片,並嘗試在這裏設置:
var imageQuery = (DataServiceQuery<Bing.ImageResult>)ar.AsyncState;
var enumerableImages = imageQuery.EndExecute(ar);
var imagesList = enumerableImages.ToList();
List<String> imList = new List<String>();
while (imList.Count != 3)
{
Bing.ImageResult tr = imagesList.First<Bing.ImageResult>();
if (tr.ContentType == "image/jpeg")
{
imList.Add(tr.MediaUrl);
}
imagesList.RemoveAt(0);
}
image1.Source = new BitmapImage(new Uri(@imList[0]));
image2.Source = new BitmapImage(new Uri(@imList[1]));
image3.Source = new BitmapImage(new Uri(@imList[2]));
當我調試,過程似乎只停留在哪裏設置的最後三個行資源。