我的所有数据照片都在服务器示例网址:http://abcd.com/images/中,我已将所有照片文件重命名为我的相册ID示例1.jpg,2.jpg 我想在网格视图中使用albumid显示这些照片
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>
答案 0 :(得分: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; }