我正在从 Bing 获取图像以显示在我的应用程序中。我按照 Bing 的指示成功检索了图像的 URL,但由于某种原因,模拟器不会显示它们!这就是我所拥有的
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]));
当我调试时,该过程似乎只是在我设置源的最后三行停止。