1

我有一个 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>

家庭和姓名显示正确。但是没有显示数字!!!

4

0 回答 0