我有一个xml文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<PhoneBook xmlns="http://tempuri.org/PhoneBook.xsd">
<Person>
<PersonItem name="name1" famil="famil1">
<Numbers>
<NumbersItem number="123456" />
<NumbersItem number="789100" />
</Numbers>
</PersonItem>
</Person>
<Person>
<PersonItem name="name2" famil="famil2">
<Numbers>
<NumbersItem number="654321" />
<NumbersItem number="111213" />
</Numbers>
</PersonItem>
</Person>
</PhoneBook>
我已使用以下内容成功将列表框绑定到此XML:
Imports <xmlns:DaftarTelephone="http://tempuri.org/PhoneBook.xsd">
Dim xmlPhoneBook = XDocument.Load(CurDir() & "\PhoneBook.xml")
Dim q = From el In xmlPhoneBook ...<PhoneBook:PersonItem>
lst.ItemsSource = q 'my listbox
这是我的XAML:
<Page.Resources>
<DataTemplate x:Key="PersonItemTemplate">
<StackPanel>
<TextBlock Text="{Binding Path=Attribute[famil].Value}"/>
<TextBlock Text="{Binding Path=Attribute[name].Value}"/>
<TextBlock Text="{Binding Path=Attribute[number].Value}"/>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid x:Name="LayoutRoot" >
<ListBox x:Name="lst" ItemsSource="{Binding}" ItemTemplate="{DynamicResource PersonItemTemplate}" />
</Grid>
系列和名称显示正确。但数字没有显示!!!