问题描述
我需要让一个控件出现在所有其他控件之上,这样它就会部分覆盖它们.
I need to make a control appear above all other controls, so it will partially overlay them.
推荐答案
如果您在布局中使用 Canvas
或 Grid
,请提供要放置的控件顶一个更高的ZIndex
.
If you are using a Canvas
or Grid
in your layout, give the control to be put on top a higher ZIndex
.
来自 MSDN:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="ZIndex Sample">
<Canvas>
<Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/>
<Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="150" Canvas.Left="150" Fill="yellow"/>
<Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="200" Canvas.Left="200" Fill="green"/>
<!-- Reverse the order to illustrate z-index property -->
<Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="300" Canvas.Left="200" Fill="green"/>
<Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="350" Canvas.Left="150" Fill="yellow"/>
<Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="400" Canvas.Left="100" Fill="blue"/>
</Canvas>
</Page>
如果您不指定 ZIndex
,面板的子项将按照指定的顺序呈现(即最后一个在顶部).
If you don't specify ZIndex
, the children of a panel are rendered in the order they are specified (i.e. last one on top).
如果您想要做一些更复杂的事情,您可以查看 ChildWindow
在 Silverlight 中是如何实现的.它覆盖了整个 RootVisual
的半透明背景和弹出窗口.
If you are looking to do something more complicated, you can look at how ChildWindow
is implemented in Silverlight. It overlays a semitransparent background and popup over your entire RootVisual
.
这篇关于如何使覆盖控件高于所有其他控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!