Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>TreeViews work differently. The Items inside a HierarchicalDataTemplate <em>are</em> TreeViewItems and any control you specify inside the HierarchicalDataTemplate will function as its Header. So, basically you are specifying that the Items in your TreeView are TreeViewItems with TreeViewItems as their headers! Instead try this:</p> <pre><code> &lt;HierarchicalDataTemplate ItemsSource="{Binding Items}"&gt; &lt;Label Content="{Binding}"/&gt; &lt;HierarchicalDataTemplate.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Path= Item.SomeData}"/&gt; &lt;/DataTemplate&gt; &lt;/HierarchicalDataTemplate.ItemTemplate&gt; &lt;/HierarchicalDataTemplate&gt; </code></pre> <p>EDIT: I could not reproduce a DataSource that produces the properties you want to bind to, so I wrote some simple code of my own that shows how it all works. Hopefully you will be able to adapt it to your needs:</p> <pre><code>&lt;TreeView ItemsSource="{Binding}" Name="Tree"&gt; &lt;TreeView.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type TreeViewItem}" &gt; &lt;Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/&gt; &lt;/Style&gt; &lt;/TreeView.ItemContainerStyle&gt; &lt;TreeView.ItemTemplate&gt; &lt;HierarchicalDataTemplate ItemsSource="{Binding Items}"&gt; &lt;Label Content="{Binding Name}"/&gt; &lt;HierarchicalDataTemplate.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Path= SomeData}"/&gt; &lt;/DataTemplate&gt; &lt;/HierarchicalDataTemplate.ItemTemplate&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.ItemTemplate&gt; &lt;/TreeView&gt; using System.Collections.Generic; using System.ComponentModel; using System.Windows; namespace TreeViewSpike { public partial class Window1 : Window { public Window1() { InitializeComponent(); List = new List&lt;ItemList&gt; { new ItemList { Name = "MyList", Items = new List&lt;Item&gt; {new Item("1"), new Item("2")} }, new ItemList { Name = "MySecondList", Items = new List&lt;Item&gt; {new Item("3"), new Item("4")} } }; Tree.DataContext = List; List[1].IsSelected = true; } public List&lt;ItemList&gt; List { get; set; } } public class ItemList: INotifyPropertyChanged { public string Name{ get; set;} private bool _isSelected; public bool IsSelected { get { return _isSelected; } set { _isSelected = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsSelected")); if(_isSelected) MessageBox.Show(Name + " selected"); } } public List&lt;Item&gt; Items { get; set; } public event PropertyChangedEventHandler PropertyChanged; } public class Item { public string SomeData { get; set; } public Item(string data) { SomeData = data; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload