Decrease indentation in TreeViewItem for deepest node
How can I decrease the left indentation of the deepest Tre开发者_运维百科eViewItem
node? For some reason WPF seem to increase this indentation by quite a bit for all but the deepest node. Looking at Window XP's tree view implementation each depth has the same left margin.
I've searched around and I can't seem to find an implementation that works yet it appears to be possible.
UPDATE: Corrected the solution
Here is a picture of the problem for reference...
And here is a picture of what you're (probably) hoping for...
NOTE: The list of files appears further to the left in the second screenshot.
After digging into this, I consider it a defect in the default TreeViewItem template. To fix this and to make any other adjustments needed, you'll need to provide your own TreeViewItem template. Starting with the default TreeViewItem template from this SO answer...
You need to change this...
<Trigger Property="HasItems" Value="false">
<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
</Trigger>
To this...
<Trigger Property="HasItems" Value="false">
<Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/>
</Trigger>
That should do it for you. By default, the system is leaving the 19 pixels of space for the exapander. Since the expander isn't needed at the leaf level, that area should be collapsed, not hidden.
精彩评论