如何使叠加控件高于所有其他控件? [英] How to make overlay control above all other controls?

查看:112
本文介绍了如何使叠加控件高于所有其他控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使一个控件出现在所有其他控件的上方,因此它将部分覆盖它们.

I need to make a control appear above all other controls, so it will partially overlay them.

推荐答案

如果在布局中使用CanvasGrid,则将控件放在较高的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.

这篇关于如何使叠加控件高于所有其他控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆