减少 TreeViewItem 中最深节点的缩进 [英] Decrease indentation in TreeViewItem for deepest node

查看:41
本文介绍了减少 TreeViewItem 中最深节点的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何减少最深的 TreeViewItem 节点的左缩进?出于某种原因,WPF 似乎为除最深节点之外的所有节点增加了相当多的缩进.查看 Window XP 的树视图实现,每个深度都有相同的左边距.

How can I decrease the left indentation of the deepest TreeViewItem 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:更正了解决方案

这是问题的图片供参考...

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.

深入研究后,我认为这是默认 TreeViewItem 模板中的一个缺陷.要解决此问题并进行所需的任何其他调整,您需要提供自己的 TreeViewItem 模板.从 this SO answer中的默认 TreeViewItem 模板开始...

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...

你需要改变这个...

<Trigger Property="HasItems" Value="false">
    <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
</Trigger>

为此...

<Trigger Property="HasItems" Value="false">
    <Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/>
</Trigger>

那应该为您做.默认情况下,系统会为扩展器留出 19 像素的空间.由于在叶级别不需要扩展器,因此该区域应该折叠而不是隐藏.

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.

这篇关于减少 TreeViewItem 中最深节点的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆