I populate a WPF tree view using data binding. Tree view items are not expanded by default.
The items in the collection the tree view binds to implement an IsExpanded
property. A tree view item binds its IsExpanded
property to the IsExpanded
property of an item in the collection.
In an attempt to make a certain tree view item visible I try successively to expand its ancestors by setting the IsExpanded
property of the items in my data collection to true
. However only the first level tree view item gets expanded and the second level tree view items become visible.
I reason this is because the hidden tree view items are not created yet. Hence some items in my collection do not have a corresponding tree view item and setting the IsExpanded
property has no effect. (But I may be wrong.)
Example
My tree view displays the file system:
- C:\
- D:\
- E:\
To make the folder D:\Users\Alex\Pictures\ visible I get the items “D:”, “Users”, “Alex” and “Pictures” from my collection and set the IsExpanded property to true. The tree view item representing “D:” gets expanded, but no further expansion happens.
- C:\
- D:\
- Users
- Garbage
- Foo
- E:\
Any advice? Thanks!