我有一个DockPanel作为我的窗口的根元素。
我还有另一个DockPanel,它本质上是一个菜单栏,被设置为停靠在root-element-DockPanel的顶部。
我想有一个图像停靠到根-元素-DockPanel的顶部,浮动在菜单栏上的DockPanel。
例如:
<DockPanel x:Name="RootDockPanel">
<Image Souce="/MyProject;component/Images/imageName.jpg" DockPanel.Dock="Top" Panel.ZIndex="3" />
<DockPanel x:Name="MenuDockPanel" DockPanel.Dock="Top" Panel.ZIndex="0">
<!-- content -->
</DockPanel>
</DockPanel>
我曾尝试将图像的Panel.ZIndex设置为比菜单栏停靠面板的Panel.ZIndex更高的值,但这不起作用。
由于ZIndex被证明是无用的,我不确定如何实现这一点,我正在寻求您的意见。
谢谢你的帮忙!
-Frinny
发布于 2011-03-24 14:52:11
我建议简单地抛弃DockPanel控件,转而使用网格。根据我的经验,DockPanel是一个设计很差的控件,也是WPF中最无用的面板控件。
发布于 2019-05-07 15:42:02
DockPanel.ZIndex
为我工作。
这里有一个例子来帮助你(它可能无法编译,我只是从内存中编写它来说明这个概念):
<DockPanel>
<Label
Background="Yellow"
Content="Foo"
DockPanel.Dock="Right"
DockPanel.ZIndex="1"
/>
<Label
Background="Green"
Content="Bar"
DockPanel.Dock="Right"
DockPanel.ZIndex="0"
/>
</DockPanel>
https://stackoverflow.com/questions/5420436
复制相似问题