There are effectively two ways to achieve this in WPF, and they are sometimes known as the wrong way and the right way. I'm not being flippant here, but the
TreeView
is one of the most abused controls in WPF because people often attempt to manipulate it directly which is messy and complex, rather than populating it using MVVM, which is a lot simpler.
WPF Guru, Josh Smith, posted an excellent tutorial on working with the
TreeView
using MVVM
here[
^]. Well worth reading and trying the sample - you will learn how easy it is to use the
TreeView
using MVVM.