zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    提交一个spark程序及spark执行器
    前端如何让服务器主动向浏览器推送数据
    h5页面移动端iPhoneX适配方法
    详说tcp粘包和半包
    mysql配置文件 /etc/my.cnf 详细解释
    【todo】MVCC原理及与锁之间的关系
    【todo】innodb表锁的底层实现原理
    【todo】innodb行锁的底层实现原理
    【todo】mysql binlog
    [todo] spring 事务的传播性
  • 原文地址:https://www.cnblogs.com/tanliang/p/2263388.html
Copyright © 2011-2022 走看看