You shouldn't be defining TreeViewItems explicitly in your ItemTemplates. The reason you can't select any of the items is that they have no parent TreeView to control selection behavior. You need to let the TreeView generate the TreeViewItem controls for you and only use the item templates to define the UI for the Headers and the bindings for their items.
Use something like this instead.
Up vote 1 down vote favorite 1 share g+ share fb share tw.
So I am having an issue with the TreeView. If I build a tree view statically, every node in the tree is selectable in that when I click on it, it highlights itself blue, indicating that node is selected. However, I am Binding to the TreeView to populate it.
Furthermore, I am binding to objects that implement Emiel Jongerius's BindableObjectBase3 class. This is a wonderful base class implementation that allows my objects to be Bindable and implement the INotifyPropertyChanged interface with the concern for manual DependencyProperty management. So this is the basic class structure (simplified from my actual objects) that I am trying to implement in a TreeView.
Public abstract class MyCustomClass : BindableObjectBase3 { private string m_strName; public virtual string Name { get { using (this. GetPropertyTracker(() => this.Name)) { return m_strName; } } set { this. SetValue(ref this.
M_strName, value, () => this.Name); } } } public class Project : MyCustomClass { private List m_steps; public List Steps { get { using (this. GetPropertyTracker(() => this. Steps)) { return m_steps; } } set { this.
SetValue(ref this. M_steps, value, () => this. Steps); } } } public class Step : MyCustomClass { private List m_loads; public List Loads { get { using (this.
GetPropertyTracker(() => this. Loads)) { return m_loads; } } set { this. SetValue(ref this.
M_loads, value, () => this. Steps); } } } public class Load : MyCustomClass { } And this is the basic XAML I use to implement the TreeView: Now all of this works fine as far as binding goes. I can bind to an ObservableCollection and as I add/remove/manipulate projects, the TreeView updates accordingly.
However, the only node in the TreeView that seems selectable is the first node (the one that is static). All of the other nodes create through dynamic Binding do not indicate that they are selected on the GUI. I would expect that they would also highlight blue when clicked on.
But instead they do nothing. Does anyone have an idea of why? Wpf xaml treeview binding link|improve this question asked Aug 24 '10 at 14:54Ristogod8911 100% accept rate.
Thank you very much. So much of figuring out this control seems to non-intuitive. I'm happy you could share your experience.
Thanks. – Ristogod Aug 25 '10 at 13:21.
My TreeView is acting just as the original poster has described. I'm able to select everything in my TreeView Control but If I select a childnode the Parent Node is what Highlights even though It binds and clicks the child. I tried structuring my code to resemble John Bowen's suggestion and still get the same results.
Here is my XAML Code: Then I use it here in my TreeView Control: The result is this screenshot, notice how the parent node D is highlighted after clicking the child node, instead of the child node being highlighted:
Can't post images so just cut and paste the URL link.I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.