silverlight元素被遮挡使用ZIndex

     对象之间的位置是由xmal的声明顺序所决定,先申明的元素默认情况下显示在后什么的元素之后,同常情况下我们会遇到元素被覆盖层叠的情况,这种情况下可使用Canvas对象的Zindex来设置其层次关系,如下图是未设置之前的图元(图1),与设置之后的图元(图2)

     

 

                (图1)                                                                                         (图2)

通过设置Zindex来控制其显示层次关系,zindex值越大表示越接近前景,层次就越高,反之值越小就层级越低。代码如下:

xaml:

 

View Code
<UserControl x:Class="Demo.MenuItemDemo"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
d:DesignHeight
="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White" MouseRightButtonDown="LayoutRoot_MouseRightButtonDown" MouseRightButtonUp="LayoutRoot_MouseRightButtonUp">

<Rectangle Stroke="Red" Fill="Blue" Height="45" HorizontalAlignment="Left" Margin="161,70,0,0" Name="rectangle1" StrokeThickness="1" VerticalAlignment="Top" Width="53" Canvas.ZIndex="2"/>
<Rectangle Stroke="Red" Fill="AntiqueWhite" Height="45" HorizontalAlignment="Left" Margin="178,82,0,0" Name="rectangle2" StrokeThickness="1" VerticalAlignment="Top" Width="53" Canvas.ZIndex="1"/>
<Rectangle Height="45" Fill="Aquamarine" HorizontalAlignment="Left" Margin="138,50,0,0" Name="rectangle3" Stroke="Red" StrokeThickness="1" VerticalAlignment="Top" Width="53" Canvas.ZIndex="3"/>
</Grid>
</UserControl>

 

转载于:https://www.cnblogs.com/tanliang/archive/2011/11/25/2263388.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值