2013-01-03 18 views
0

我的XML文件看起來是這樣的結合圖像在Windows Phone應用程序

<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> 

我的XAML文件看起來像

<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> 
我xaml.cs

文件I有加

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; 

你能幫我怎麼綁定圖片嗎

回答

1

只需將名稱ImageSource更改爲圖像(圖像是您的Person類的屬性名稱即可)

<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> 
相關問題