从 DataTemplate 访问 ItemsPanel 属性
在带有 Canvas ItemsPanel 的 ListBox 的上下文中,我需要访问多个 DataTemplate 中每个控件的 Cavas.ZIndex(列表显示多种对象类型)。使用 a 是不够的
<ListBox.ItemContainerStyle>
<Setter Property="Canvas.ZIndex" ..... />
,因为有多个数据模板,每个模板都有多个控件,我想控制每个控件的绝对 zindex。 这可能吗?
In the context of a ListBox with Canvas ItemsPanel I need to access Cavas.ZIndex for each control within the multiple DataTemplates (the list displays several object types). Its not enough to use a
<ListBox.ItemContainerStyle>
<Setter Property="Canvas.ZIndex" ..... />
as there are several data templates each with several controls and I would like to control the absolute zindex of each control.
Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,这是不可能的
原因是当 ListBox 呈现时,它会像这样呈现(假设您指的是 你的其他问题):
如你所见,每个ListBoxItem都呈现为一组嵌套控件。您不能将所有 TextBlock 绘制在所有 Line 之上,因为它们并不都共享相同的父容器,并且 ZIndex 用于对同一父容器内的项目进行排序。
解决方法是使用两个相互重叠的单独的 ItemsControl。因此,所有线条都将绘制在底部 ItemsControl 上,而所有 TextBlock 将绘制在顶部 ItemsControl 上。
To my knowledge, this is not possible
The reason is that when a ListBox renders, it renders like this (assuming you're referring to the same code you had in your other question):
As you can see, each ListBoxItem is rendered as a group of nested controls. You cannot have all your TextBlocks drawn on top of all your Lines because they do not all share the same parent, and ZIndex is used to order items that are within the same parent container.
A workaround would be to use two separate ItemsControls drawn on top of each other. So all your Lines would be drawn on the Bottom ItemsControl while all the TextBlocks would be drawn on the Top ItemsControl.