繁体   English   中英

如何在Windows Phone 7应用程序中显示来自后台的图像?

[英]How do I display images from back office in windows phone 7 application?

我正在Windows Phone 7中构建我的第一个应用程序。我需要显示来自Web服务的一些数据以及图像。 我能够显示数据,但不知道如何显示图像。 可以输入需要更新的新数据。 该图像将来自后台,而路径将来自Web服务。 我的网络服务是:

 <string><NewDataSet>
  <UserDetails>
    <id>5</id>
    <News_Title>Audit of Electricity Companies</News_Title>
    <News_Description> Rejecting the contention of private power distributors, the Delhi government today ordered an audit of their finances by the government's national auditor or Comptroller and Auditor General (CAG), fulfilling yet another election promise of the Aam Aadmi Party.

</News_Description>
    <Date_Start>2014-01-03</Date_Start>
    <image_path>news.png</image_path>
  </UserDetails>

将会有1个以上的数据。 我可以显示news_Title,news_description和Date_start。 我的cs代码是

 public class Newss
    {
        public string News_Title { get; set; }
        public string News_Description { get; set; }
        public string Date_Start { get; set; }
    }




    public News()
    {
        InitializeComponent();

        KejriwalService.aapSoapClient client = new KejriwalService.aapSoapClient();
        client.getarvindNewsCompleted += new EventHandler<KejriwalService.getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted);
        client.getarvindNewsAsync();
    }

    void client_getarvindNewsCompleted(object sender, KejriwalService.getarvindNewsCompletedEventArgs e)
    {
        string result = e.Result.ToString();
        List<Newss> listData = new List<Newss>();
        XDocument doc = XDocument.Parse(result);
        // Just as an example of using the namespace...
        //var b = doc.Element("NewDataSet").Value;
        foreach (var location in doc.Descendants("UserDetails"))
        {
            Newss data = new Newss();
            data.News_Title = location.Element("News_Title").Value;

           // data.News_Description = location.Element("News_Description").Value;
            data.Date_Start = location.Element("Date_Start").Value;
            listData.Add(data);
        }
        listBox1.ItemsSource = listData;

    }

我的xaml文件是

 <ScrollViewer Margin="12,17,-12,144" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto" AllowDrop="False" ManipulationMode="Control">
            <ListBox Name="listBox1" Margin="38,86,38,562">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">

                            <TextBlock Text="{Binding Path=News_Title}"></TextBlock>
                            <TextBlock Text="{Binding Path=News_Description}"></TextBlock>
                            <TextBlock Text="{Binding Path=Date_Start}"></TextBlock>

                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>

将此添加到您的模型

public class Newss
{
    public string News_Title { get; set; }
    public string News_Description { get; set; }
    public string Date_Start { get; set; }
    public string Image_Path { get; set; }
}

在foreach循环中设置image属性

foreach (var location in doc.Descendants("UserDetails"))
    {
        Newss data = new Newss();
        data.News_Title = location.Element("News_Title").Value;

       // data.News_Description = location.Element("News_Description").Value;
        data.Date_Start = location.Element("Date_Start").Value;
        Newss.Image_Path  = location.Element("image_path").Value
        listData.Add(data);
    }

在您的Xaml中

<ScrollViewer Margin="12,17,-12,144" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto" AllowDrop="False" ManipulationMode="Control">
        <ListBox Name="listBox1" Margin="38,86,38,562">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">

                        <TextBlock Text="{Binding Path=News_Title}"></TextBlock>
                        <TextBlock Text="{Binding Path=News_Description}"></TextBlock>
                        <TextBlock Text="{Binding Path=Date_Start}"></TextBlock>
                        <Image Source="{Binding Path=Image_Path}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>

显然,确保来自xml有效负载的Image_Path数据是有效的uri,我首先将其设置为静态图像,例如“ http://static.bbci.co.uk/frameworks/barlesque/2.59.4/ orb / 4 / img / bbc-blocks-dark.png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM