There are several ways to populate a treeview with treeview items and they are:
Declaratively in your XAML code - suitable for cases when the treeview items structure is known during the implementation phase and does not change in time.
Programmatically from the code-behind - use when the treeview structure can be changed during run-time by the user or other application logic.
Using data binding - use when the treeview structure is described in data module.
Each one of the approaches described above is applicable for certain cases and that’s why you have to choose the one that best fits your requirements.
Bear in mind that the XAML file is the best place to declare your user interface; use the code-behind only when you cannot do that in XAML.