你如何在 WPF C# 中获得 treeviewitem 的级别? [英] How do you get the level of a treeviewitem in WPF C#?
问题描述
在 WPF C# 中如何获得 treeviewitem 的级别?在 Windows 窗体中,树视图类有一个 .Level 成员,但 WPF C# 似乎没有.
How do you get the level of a treeviewitem in WPF C#? In windows forms there is a .Level member of the treeview class but there does not seem to be one for WPF C#.
推荐答案
构建视图模型.
视图模型为您提供了比没有树视图更大的灵活性.帮自己一个忙,不要走视觉树,如果一个父节点不可见,它可能被虚拟化了,你的水平(或深度)图将是错误的.构建一个视图模型来包装您的数据并知道它处于什么级别.
A View model gves you greater flexibility with the treeview than you can achieve without it. Do yourself a favour, dont walk the visual tree, If a parent node is not visible, it could be virtualised away and your level (or depth) figure will be wrong. build a view model that wraps your data and knows at what level it is at.
查看此处发布的答案.
回答链接一(您需要向您的视图模型 - 级别)
answer link one (you would add another property to your view model - level)
这篇关于你如何在 WPF C# 中获得 treeviewitem 的级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!