Xaml(Windows Phone 8和Silverlight)用户控制堆栈问题



我在网格中放置了一个用户控件。在网格内,我也在画线。这些行显示在用户控件的上方。

当用户点击我的用户控件时,我会显示用户控件的另一部分,一个xaml元素(使其可见),我需要它出现在绘制的线上方。

我试过Canvas.ZIndex。它似乎只适用于我的用户控制中的元素。如果我将usercontrols ZIndex设置为高,那么它将全部显示在线上。

以下是Min的工作示例:

我需要蓝色正方形保持在黑线下方,黄色椭圆保持在黑线上方。

--主页——

<UserControl xmlns:SWE_UserControlOverlap="clr-namespace:SWE_UserControlOverlap"  x:Class="SWE_UserControlOverlap.MainPage"
    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">
        <SWE_UserControlOverlap:SWE />
        <Line Stroke="Black" StrokeThickness="10" Stretch="Fill" X1="0" Y1="0" X2="1" Y2="1"></Line>
    </Grid>
</UserControl>

--用户控制——

<UserControl x:Class="SWE_UserControlOverlap.SWE"
    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">
        <Rectangle Fill="Blue" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp_1"></Rectangle>
        <Ellipse Margin="100" Fill="Yellow" ></Ellipse>
    </Grid>
</UserControl>

不要在控件上设置ZIndex,只需为子控件修改它。

<Line Canvas.ZIndex="1" />
<Rectangle Canvas.ZIndex="0" />
<Ellipse Canvas.ZIndex="2" />

正如我在网络上的各个地方发现的那样,这是不可能的。

最新更新