如何使 ui 元素的 zindex 相对于父画布而不是包含画布?
基本上,我试图通过在 1 的阴影元素(也是路径)上放置 ZIndex 并在另一个 UI 元素 2 上放置 zindex 来在用户控件中的简单 Path 元素上创建阴影效果。这 2 个元素是在根是画布的用户控件中,并按用户控件中的预期工作。
我还有一个包含此控件的画布,其中包含该控件的 2 个实例,我希望每个实例的阴影元素显示在另一个的非阴影元素下方。它不起作用,并且一个控件的阴影出现在其他非阴影元素的顶部。如果我更改用户控件的父画布的 ZIndex 索引,它会将用户控件中的两个元素放在其他用户控件元素的顶部。我认为这是因为 ZIndex 仅相对于包含的画布而不是所有画布。
在不将所有 UI 元素放在同一画布上的情况下解决此问题的最佳方法是什么?
Basically, I'm trying to create a shadow effect on a simple Path element in a user control by putting a ZIndex on the shadow element (also a Path) of 1 and a zindex on the other UI element of 2. These 2 elements are in a user control where the root is a canvas and work as expected in the user control.
I also have a containing canvas that contains 2 instances of this control, where I want the shadow element of each to appear underneath the other's non-shadow element. Its not working and the shadow of one control are appearing on top of the others non-shadow element. If I change the parent canvas's ZIndex index for the user control it puts both elements in the user control on top of the other user controls elements. I assume this is because the ZIndex is only relative to the containing canvas and not all canvases.
What's the best way to go about fixing this without putting all of the UI elements on the same canvas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕您将不得不找到一种方法将您的路径组装到一个画布中。当渲染 Canvas 时,它仅尊重其直接子级的 Z-Index。您可以按如下方式进行测试:
在上面的示例中,即使蓝色矩形的 ZIndex 为 16(大于绿色矩形的 ZIndex),它也会呈现在下方,因为它包含在 ZIndex 为 的 Canvas 中5. 移除包含的画布,蓝色矩形渲染在绿色上方。
I'm afraid you are going to have to find a way to assemble your paths into a single Canvas. When a Canvas is rendered it respects the Z-Index of its immediate children only. You can test this as follows:
In the above example, even though the blue rectangle has a ZIndex of 16, which is greater than the ZIndex of the Green rectangle, it is rendered beneath, because it is contained within a Canvas with a ZIndex of 5. Remove the containing canvas and the blue rectangel renders above the green.