C# 如何在windows phone 7Thi中从web服务检索多个图像

C# 如何在windows phone 7Thi中从web服务检索多个图像,c#,windows-phone-7,C#,Windows Phone 7,我正在windows phone 7中构建一个应用程序,在该应用程序中,我需要在单个图像视图中从web服务检索多个图像,并且当用户滑动图像时,图像应该会更改。我试过以下方法: 我的xaml: <Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="79,61,72,503" Height="187" /> 这是我要显示图像的

我正在windows phone 7中构建一个应用程序,在该应用程序中,我需要在单个图像视图中从web服务检索多个图像,并且当用户滑动图像时,图像应该会更改。我试过以下方法:

我的xaml:

<Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch" 
 VerticalAlignment="Stretch" Margin="79,61,72,503" Height="187" /> 

这是我要显示图像的图像视图

cs代码:

 public class Rest
    {

        public string restaurant_image { get; set; }
        public BitmapImage ImageBind { get; set; }
    }

    public const string RestXml = "Rest.xml";

    public Restaura()
    {
        InitializeComponent();
        LoadData();
    }

    private void LoadData()
    {
        bool isSuccess;
        //try to load data from iso store
        var doc = ReadXml(out isSuccess);

        if (isSuccess) PopulateList(doc);

        //if failed (data doesn't exists in iso store), download data from web service

        else
        {
            RahmService.RahmSoapClient client = new RahmService.RahmSoapClient();
            client.getRestaurantLocationAllCompleted += new EventHandler<RahmService.getRestaurantLocationAllCompletedEventArgs>(client_getRestaurantLocationAllCompleted);
            client.getRestaurantLocationAllAsync();
        }
    }

    void client_getRestaurantLocationAllCompleted(object sender, RahmService.getRestaurantLocationAllCompletedEventArgs e)
    {
        var doc = XDocument.Parse(e.Result);
        PopulateList(doc);
        WriteXml(doc);
    }
公共类Rest
{
公共字符串\u图像{get;set;}
公共位图图像ImageBind{get;set;}
}
public const string RestXml=“Rest.xml”;
公共餐厅()
{
初始化组件();
LoadData();
}
私有void LoadData()
{
bool-issucess;
//尝试从iso存储加载数据
var doc=ReadXml(out issucess);
if(isSuccess)大众列表(doc);
//如果失败(iso存储中不存在数据),请从web服务下载数据
其他的
{
RahmService.RahmSoapClient client=新的RahmService.RahmSoapClient();
client.getRestaurantLocationalCompleted+=新事件处理程序(client\u getRestaurantLocationalCompleted);
client.getRestaurantLocationLasync();
}
}
无效客户端\u GetRestaurantLocationalCompleted(对象发送方,RahmService.GetRestaurantLocationalCompletedEventArgs e)
{
var doc=XDocument.Parse(e.Result);
大众主义者(doc);
WriteXml(doc);
}

在这里我没有得到任何结果。请帮我编写代码

您的xaml应该是这样的

<ListBox  Name="ListBoxProduct" >
  <ListBox.ItemTemplate>
    <DataTemplate>
     <StackPanel>
     <Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch" 
      VerticalAlignment="Stretch" Height="187" /> 
    </StackPanel>                    
   </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

暗藏

private void PopulateList(XDocument doc)
    {
       List<Rest> restList = new List<Rest>();
        foreach (var location in doc.Descendants("UserDetails"))
        {
            Rest data = new Rest();
            data.restaurant_image = location.Element("restaurant_image").Value;
            data.ImageBind = new BitmapImage(new Uri(@" http://........" 
                                             + data.restaurant_image, UriKind.Absolute));
            restList.Add(data);

        }
         ListBoxProduct.ItemsSource= restList;
    }
private void PopulateList(XDocument doc)
{
List restList=新列表();
foreach(文档子体(“UserDetails”)中的变量位置)
{
Rest数据=新的Rest();
data.restaurant\u image=location.Element(“restaurant\u image”).Value;
data.ImageBind=新的位图图像(新的Uri(@)http://........" 
+data.restaurant_image,UriKind.Absolute);
restList.Add(数据);
}
ListBoxProduct.ItemsSource=restList;
}

尝试此操作。

是否流行列表有完整定义???@Jaihind Hey如果可能,请添加必要的代码我收到错误:System.Windows.Controls.listbox不包含itemsource的定义ITS ItemsSource not itemsource。我在ans上也做了一些改动,看看。嘿,我觉得有些问题。应用程序正在运行,但没有响应。图像不出现这是你的服务问题。我建议您在获取图像后将其保存在隔离存储中,而不是从服务中一次又一次地获取这些图像。我正在存储图像,但为此,我需要获取一次图像。