Thank you for the picture and code snippet, I was able to understand your scenario and question.
Let me first try to explain the structure of the TreeViewItem. So, in the template you can find a IndentContainer
(which is connected to the ItemsIndent property) and Expand ToggleButton
(for expanding its children if any). We do not have different templates for the items if they have children or not. So, we should ensure that all treeview items with and without children are aligned, e.g. Item 2.1 and Item 2.2:
Item 2.1 (leaf node)
Item Level 3
However, for your scenario I can suggest you the following: you can set ItemsIndent
property of the TreeView to 0
and control the indent trough the Margin
of the TreeViewItem using ItemContainerStyle
of the treeview:
is a property of the items in your ViewModel.
For your convenience I implemented this approach in the attached project. Please take a look at it and let us know if it works for you.
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.