tags:

views:

89

answers:

0

Hi

I recently got it working to bind my XML document to my treeview by doing the following in the code behind file:

XDocument doc = XDocument.Load("path\\dsCurrent.xml");

_treeView.DataContext = doc;

and the following in the XAML:

<Window.Resources>
        <HierarchicalDataTemplate ItemsSource="{Binding Path=Elements}" x:Key="TVTemplate">
            <TreeViewItem Header="{Binding Path=Name}"/>
            <!--<TreeViewItem Header="{Binding Path=Attribute[Title].Value}"/>-->
        </HierarchicalDataTemplate>
    </Window.Resources>
    <StackPanel>
        <TreeView x:Name="_treeView" ItemsSource="{Binding Path=Root.Elements}" ItemTemplate="{StaticResource TVTemplate}"/>
    </StackPanel>

Now my XML file looks like this:

- <Shippers>
  <ShipperID>1</ShipperID> 
  <CompanyName>Speedy Express</CompanyName> 
  <Phone>(503) 555-9831</Phone> 
- <Orders>
  <OrderID>10249</OrderID> 
  <CustomerID>TOMSP</CustomerID> 
  <EmployeeID>6</EmployeeID> 
  <OrderDate>1994-08-05T00:00:00+02:00</OrderDate> 
  <RequiredDate>1994-09-16T00:00:00+02:00</RequiredDate> 
  <ShippedDate>1994-08-10T00:00:00+02:00</ShippedDate> 
  <ShipVia>1</ShipVia> 
  <Freight>11.61</Freight> 
  <ShipName>Toms Spezialitäten</ShipName> 
  <ShipAddress>Luisenstr. 48</ShipAddress> 
  <ShipCity>Münster</ShipCity> 
  <ShipPostalCode>44087</ShipPostalCode> 
  <ShipCountry>Germany</ShipCountry> 
- <_x005B_Order_x0020_Details_x005D_>
  <OrderID>10249</OrderID> 
  <ProductID>14</ProductID> 
  <UnitPrice>18.6</UnitPrice> 
  <Quantity>9</Quantity> 
  <Discount>0</Discount> 
  </_x005B_Order_x0020_Details_x005D_>

When I start the app, my treeview gets created correctly, except it does not put the actual ShipperID value in as the name of the node, it shows "SupplierID". This is the same for all the nodes. How can I bind the Header of the treeview items so that it shows the values? I tried binding the header to Value but it then shows a whole bunch of information. How can I select specifically which value to set as the header for the treeview items