连接 wpf TreeView 中节点的虚线
我正在寻找一种方法来绘制虚线来连接 wpf TreeView 中的节点。问题似乎是我使用 HierarchicalDataTemplate
而不是用 TreeViewItem
填充 TreeView
。
我找到了这个帖子: http://social. msdn.microsoft.com/forums/en-US/wpf/thread/30cb182c-9419-40bd-946e-87971515fb95/
女巫在填充 TreeViewItem
时很好地解决了这个问题,但是我的问题是,我如何用 HierarchicalDataTemplate 解决它?
我的模板看起来像这样:
<HierarchicalDataTemplate DataType = "{x:Type Team}" ItemsSource ="{Binding Path=Players">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<DataTemplate DataType = "{x:Type Player}">
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate >
有关如何解决问题的任何解决方案或好的提示吗?
I am looking for a way to draw dotted lines to connect nodes in a wpf TreeView
. The problem seems to be that i am using HierarchicalDataTemplate
instead of populating the TreeView
with TreeViewItem
s.
I have found this post:
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/30cb182c-9419-40bd-946e-87971515fb95/
Witch solves it great in the case when populating it TreeViewItem
s but my question is, how would i solve it with HierarchicalDataTemplate
?
My template look something like this:
<HierarchicalDataTemplate DataType = "{x:Type Team}" ItemsSource ="{Binding Path=Players">
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<DataTemplate DataType = "{x:Type Player}">
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate >
Any solution or good hints on how to solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,最简单的方法是将代码添加到 itemstyle 中
The easiest ways, in my opinion, was to add the code in the itemstyle
在我看来,解决此类问题的最简单方法是:
SetParentDecorator(Child, this)
以便后代装饰器可以找到其父级这种方法不需要太多代码并且完全可靠,因为它不关心您正在使用哪种面板、滚动如何工作,甚至树的实际构建方式。装饰器只知道它的工作并执行它:它只是在它自己和它的祖先装饰器之间画线。
In my opinion the easiest way to solve this kind of problem is:
SetParentDecorator(Child, this)
so that descendant decorators can find their parentThis approach doesn't take much code and is totally reliable, since it doesn't care what kind of panels you are using, how scrolling works, or even how the tree is actually built. The decorator just knows its job and does it: It just draws lines between itself and its ancestor decorators.