Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
I am trying to bind a list to a treeview, but currently i can only get the First item in the list to show in my treeview
 
I have a Person class with 4 string items in it.
 
I'm binding to a property with a List
 
My xaml is
 <TreeView>
<TreeViewItem Header="People">
<TextBlock>
<TextBlock Text={Binding GetPersons/FirstName}/>
<TextBlock Text={Binding GetPersons/LastName}/>
</TextBlock>
</TreeViewItem>
<TreeView>
 
I've tried adding the itemsSource at the Treeview level, but i don't think my syntax is correct.
 
Result i'm looking for is that on root expand i have 4 entries.
Posted 25-Sep-12 6:10am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should take a look at the bottom of this page:
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx[^]
<treeview>
  <treeviewitem header="Employee1">
    <treeviewitem header="Jesper" />
    <treeviewitem header="Aaberg" />
    <treeviewitem header="12345" />
  </treeviewitem>
 <treeviewitem header="Employee2">
    <treeviewitem header="Dominik" />
    <treeviewitem header="Paiha" />
    <treeviewitem header="98765" />
  </treeviewitem>
</treeview>
 
To use a text box I do something like:
  <treeviewitem>
     <treeviewitem.header>
        <TextBlock Text={Binding GetPersons/FirstName}/>
     </treeviewitem.header>
</treeviewitem>
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 25-Sep-12 15:20pm
   
That's it, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100