Windows phone 7 在windows phone应用程序中将图像从xml绑定到列表框
我的xml文件如下所示Windows phone 7 在windows phone应用程序中将图像从xml绑定到列表框,windows-phone-7,linq-to-xml,Windows Phone 7,Linq To Xml,我的xml文件如下所示 <people><person> <firstname>venakt</firstname> <lastname>es</lastname> <age>27</age> <Image>http://www.livetut.com/wp-content/uploads/2012/06/Logo1.png</Image> </person><
<people><person> <firstname>venakt</firstname> <lastname>es</lastname> <age>27</age> <Image>http://www.livetut.com/wp-content/uploads/2012/06/Logo1.png</Image> </person></people>
你能帮我如何绑定一个图像吗?只需将名称ImageSource更改为image(image是Person类的属性名..so)
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding ImageSource}" Height="120" Width="120" HorizontalAlignment="Center" VerticalAlignment="Center" Tap="textBlock1_tap" />
<TextBlock Text="{Binding UserName}" Style="{StaticResource PhoneTextSubtleStyle}" Width="100" TextAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
public string Image { get { return Image; } set { Image = value; } }
XDocument loadedData = XDocument.Load("People.xml");
var data = from query in loadedData.Descendants("person")
select new Person
{
FirstName = (string)query.Element("firstname"),
LastName = (string)query.Element("lastname"),
Image= query.Element("Image").Attribute("url").Value
};
listBox.ItemsSource = data;
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding Image}" Height="120" Width="120" HorizontalAlignment="Center" VerticalAlignment="Center" Tap="textBlock1_tap" />
<TextBlock Text="{Binding UserName}" Style="{StaticResource PhoneTextSubtleStyle}" Width="100" TextAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>