C# 使用JSON.Net从web下载后在视图中设置图像
假设我的xaml中有3个图像视图。我正在从服务器下载图像&现在我想在图像视图中设置这些图像。我该怎么做?请帮忙! 我的代码:C# 使用JSON.Net从web下载后在视图中设置图像,c#,image,windows-phone-7,json.net,C#,Image,Windows Phone 7,Json.net,假设我的xaml中有3个图像视图。我正在从服务器下载图像&现在我想在图像视图中设置这些图像。我该怎么做?请帮忙! 我的代码: void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { //parse data var container = DeserializeFromJson<DataJsonAttribut
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//parse data
var container = DeserializeFromJson<DataJsonAttributeContainer>(e.Result);
//load into list
for (int i = 0; i < container.MyBookList.Count; i++)
{
newData[i] = new data();
newData[i].id = container.MyBookList[i].ID;
newData[i].title = container.MyBookList[i].TITLE;
newData[i].type = container.MyBookList[i].TYPE;
newData[i].price = container.MyBookList[i].PRICE;
newData[i].downloadLink = container.MyBookList[i].DOWNLOADLINK;
string file_name = newData[i].downloadLink.ToString();
string image_uri = "http://www.banglanews24.com/images/imgAll/" + file_name;
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(image_uri), wc);
}
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
try
{ //I can set just one image here....what should I do ?
BitmapImage image = new BitmapImage();
image.SetSource(e.Result);
image1.Source = image;
}
catch (Exception ex)
{
//Exception handle appropriately for your app
}
}
else
{
//Either cancelled or error handle appropriately for your app
}
}
void webClient\u DownloadStringCompleted已完成(对象发送方,DownloadStringCompletedEventArgs e)
{
//解析数据
var container=反序列化fromJSON(e.Result);
//载入列表
for(int i=0;i
这应该可以做到:
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//parse data
var container = DeserializeFromJson<DataJsonAttributeContainer>(e.Result);
//load into list
for (int i = 0; i < container.MyBookList.Count; i++)
{
newData[i] = new data();
newData[i].id = container.MyBookList[i].ID;
newData[i].title = container.MyBookList[i].TITLE;
newData[i].type = container.MyBookList[i].TYPE;
newData[i].price = container.MyBookList[i].PRICE;
newData[i].downloadLink = container.MyBookList[i].DOWNLOADLINK;
string file_name = newData[i].downloadLink.ToString();
string image_uri = "http://www.banglanews24.com/images/imgAll/" + file_name;
Uri uri = new Uri(image_uri, UriKind.Relative);
ImageSource imgSource = new BitmapImage(uri);
if (i==0) image1.source = imgSource;
else if (i==1) image2.source = imgSource;
else if (i==2) image3.source = imgSource;
etc
}
void webClient\u DownloadStringCompleted已完成(对象发送方,DownloadStringCompletedEventArgs e)
{
//解析数据
var container=反序列化fromJSON(e.Result);
//载入列表
for(int i=0;i
你会发现,当你给它一个图像URI时,你的图像会自动下载。首先,确保多次调用OpenReadAsync。OpenReadAsync被多次调用。我确定。你想实现什么。看起来你只有一个图像控件来显示多个图像。什么是图像1?我有3个图像控件在我的xaml中显示3个不同的下载图像。image1是xaml中的图像控件。图像控件为:image1、image2、image3。image1.source=image\u uri出现错误。“错误1无法将类型“字符串”隐式转换为“System.Windows.Media.ImageSource”