TabControl 中的 WPF zIndex
我试图让 zIndexing 在自定义 UserControl 上工作,但是当它在 TabControl 内弹出时,它会剪辑控件的底部,如下所示:
这是我的 XAML
<StackPanel Panel.ZIndex="1">
<TabControl Name="TabCtrlMain" Panel.ZIndex="2">
<TabItem Name="TabItmOrdrLst" Visibility="Collapsed" Panel.ZIndex="3" >
<StackPanel Panel.ZIndex="4">
<ri:OrderList x:Name="OrderList" Panel.ZIndex="5" />
<Rectangle Fill="Orange" Height="80" Width="300" />
</StackPanel>
</TabItem>
</TabControl>
<Rectangle Fill="Blue" Height="80" Width="300" />
</StackPanel>
I am trying to get zIndexing working on a custom UserControl but, it clips the bottom of the control when it pops up inside a TabControl as shown:
This is my XAML
<StackPanel Panel.ZIndex="1">
<TabControl Name="TabCtrlMain" Panel.ZIndex="2">
<TabItem Name="TabItmOrdrLst" Visibility="Collapsed" Panel.ZIndex="3" >
<StackPanel Panel.ZIndex="4">
<ri:OrderList x:Name="OrderList" Panel.ZIndex="5" />
<Rectangle Fill="Orange" Height="80" Width="300" />
</StackPanel>
</TabItem>
</TabControl>
<Rectangle Fill="Blue" Height="80" Width="300" />
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从您发布的图像来看,用户控件似乎有某种模拟弹出窗口(“注释”窗格),它是 UserControl 的子级。 如果是这种情况,如果 Notes 面板不是 OrderList 布局计算的一部分,则可以解释剪辑的情况。 考虑使 Notes 控件成为真正的弹出窗口,或者使用 Expander 之类的东西,它在展开时可以告诉它的父级(UserControl)它需要更多空间来呈现。
值得注意的是,像 StackPanel 这样的容器将始终“堆叠”其子控件(因此得名),这意味着子控件永远不会重叠。 因此,在其任何子级上设置 Z 索引是没有意义的。 我建议使用 Grid 或 Canvas 作为您想要重叠控件的容器,然后设置它们的 Z-Index。 另外,请记住,Z-Index 仅在控件的直接父级上下文中相关,因此如上例所示为所有控件提供 Panel.Zindex="n" 是行不通的。
据我所知,这个问题是布局问题,而不是Z-index问题。
From the image you posted, it looks as though the user control has some sort of a simulated popup window (the Notes pane), which is a child of the UserControl. If this is the case, it might explain the clipping if the Notes panel is not part of the OrderList's layout calculations. Consider making the Notes control a true popup window, or else use something like an Expander which, when expanded, can tell it's parent (the UserControl) that it requires more space to render.
It's worth noting that containers like StackPanel will always "stack" their child controls (hence the name), meaning that child controls will never overlap. For this reason, setting the Z-index on any of it's childred is meaningless. I'd suggest using Grid or Canvas as containers of you want to overlap controls and then set their Z-Index. Also, remember that Z-Index is only relevant in the context of the control's immediate parent, so giving all controls Panel.Zindex="n" as in the above example won't work.
From what I can see, this problem is a layout problem, not a Z-index problem.
从您的示例中不清楚您期望 ZIndex 做什么。 ZIndex 仅影响同一容器中元素的相对堆叠,因此示例中的所有 ZIndex 设置都不会产生任何效果。 无论 OrderList 与其任何子项之间的 ZIndex 相对值如何,TabItem 都会剪切 OrderList。
It is unclear from your example what you expect the ZIndex's to do. ZIndex only affects the relative stacking of elements in the same container so none of the ZIndex settings you have in your example will have any effect. The OrderList will be clipped by the TabItem regardless of the relative values of ZIndex between it and any of its children.
也许您想将 UserControl 从 StackPanel 中分离出来。 要在 Z 平面中放置元素,您可以做的事情是使用网格作为最外面的容器(如果您还没有这样做),并使用它作为布局元素的指南。 由于网格内的项目可以占据相同的空间,并且根据它们声明的顺序进行 z 排序,因此您也许能够获得您正在寻找的功能。
不确定这是否适合您想要做的事情,但值得一试。 容器内的项目将在其父容器的边界处被剪切,因此为了完成您正在寻找的内容,我认为 UserControl 必须是 StackPanel 的同级而不是它的子级。
Maybe you want to break the UserControl out of the StackPanel. Something you can do to play around with the element placement in the Z plane is to use a Grid as the outermost container (if you're not doing so already) and use this as a guide to laying out your elements. Since items inside of a grid can occupy the same space and are z-ordered based on the order in which they're declared, you might be able to get the functionality you're looking for.
Not sure if this fits what you're trying to do, but it's worth a try. Items within a container are going to be clipped at the boundaries of their parent container, so to accomplish what you're looking for I would think the UserControl would have to be a sibling of the StackPanel instead of being a child of it.