views:

89

answers:

1

Given xml that looks like this:

<Root>
    <Fruittree name="Apple" ID="2">
     <Branch name="West" ID="1">
      <Fruit name="Foo">
      <Fruit name="Bar">
     </Branch>
    </Fruittree>
    <!-- more fruitrees etc... -->
</Root>

Using xaml with a XmlDataProvider and a DataTemplate, I want to display a list, perhaps in a listbox:

Apple - West - Foo
Apple - West - Bar

So, an item in the list for each Fruit name in the 3rd level of xml.

A: 

Use a binding to make current location be Root/Fruittree, and use this template.

<DataTemplate x:Key="flattenTemplate">
    <TextBlock>
     <TextBlock.Text>
      <MultiBinding StringFormat="{} {0} - {1} - {2}">
       <Binding XPath="./Fruit/Branch/@Name" />
       <Binding XPath="./Branch/@Name" />
       <Binding XPath="./@Name" />  
      </MultiBinding>
     </TextBlock.Text>
    </TextBlock>
</DataTemplate>
Ian Kelling