-1

我的所有数据照片都在服务器示例 url:http ://abcd.com/images/并且我已将所有照片文件重命名为我的相册 ID 示例 1.jpg,2.jpg 并且我想使用其中的相册 ID 显示这些照片网格视图

class AlbumData
{
    public Int32 AlbumId { get; set; }
    public String Name { get; set; }
    public String Language { get; set; }
    public String Actors { get; set; }
    public String Director { get; set; }
    public String MusicDirector { get; set; }
    public String Year { get; set; }
}

private void Search_Click(object sender, RoutedEventArgs e)
    {
        WebClient webclient = new WebClient();
        webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webclient_DownloadStringCompleted);
        webclient.DownloadStringAsync(new Uri("http://albums.abcd.com/v1/Albums/English/1"));//--getting data using xml 

    }
    void webclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            MessageBox.Show("error");

        }


        XElement XmlTweet = XElement.Parse(e.Result);
        listBox1.ItemsSource = from tweet in XmlTweet.Descendants("Album")
                               select new AlbumData()
                               {
                                  Name = tweet.Element("Name").Value,
                                  //--how to display image---//
                               };
    }

请帮我举个例子

            <DataTemplate>
                <StackPanel>
                    <Image Source="{Binding ImageSource}" Height="100" Width="100" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    <TextBlock Text="{Binding Name}" Foreground="#FFC8AB14" FontSize="15" Width="120" TextAlignment="Center" TextWrapping="Wrap" />
                    <!--<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="8" Width="100" TextAlignment="Center" />-->
                    <!--<TextBlock Text="{Binding MusicDirector}" TextWrapping="Wrap" FontSize="8" Width="100" TextAlignment="Center"  />-->
                    <!--<TextBlock Text="{Binding UserName}" Style="{StaticResource PhoneTextSubtleStyle}" Width="100" TextAlignment="Center"/>-->
                </StackPanel>
            </DataTemplate>
4

1 回答 1

1

假设您的图像的 ElementName 是ImageUri,您必须将您的 ItemsSource 更改为:

listBox1.ItemsSource = 
    from tweet in XmlTweet.Descendants("Album")
    select new AlbumData()
    {
        Name = tweet.Element("Name").Value,
        ImageSource = new BitmapImage(new Uri(tweet.Element("ImageUri"), UriKind.Relative));
    };

AlbumData 需要扩展

public BitmapImage ImageSource { get; set; }
于 2013-09-01T11:38:42.127 回答