[英]Xaml (Windows Phone 8 & Silverlight) usercontrol stacking issue
I have a usercontrol that I am placing in a grid. 我有一个放置在网格中的用户控件。 Inside the grid I am also drawing lines. 在网格内部,我也在画线。 These lines appear above the usercontrol like they should. 这些行像应显示在usercontrol上方一样。
When the user clicks on my usercontrol, I am showing another part of the usercontrol, an xaml element (making it visible) and I need it to appear above the drawn lines. 当用户单击我的用户控件时,我正在显示用户控件的另一部分,一个xaml元素(使其可见),并且需要它出现在绘制的线条上方。
I've tried Canvas.ZIndex. 我已经尝试过Canvas.ZIndex。 That seems to only work with elements inside my usercontrol. 这似乎只适用于我的usercontrol内部的元素。 If I set the usercontrols ZIndex high, then it all appears above the lines. 如果我将用户控件ZIndex设置为高,则所有这些都显示在行上方。
Here is the Min working example: 这是Min的工作示例:
I need the Blue square to stay below the black line and the yellow ellipse to be above the black line. 我需要蓝色正方形保持在黑线下方,黄色椭圆保持在黑线上方。
--Main Page-- - 主页 -
<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-- --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>
Don't set a ZIndex on the control, just modify it for the sub controls. 不要在控件上设置ZIndex,只需对其子控件进行修改即可。
<Line Canvas.ZIndex="1" />
<Rectangle Canvas.ZIndex="0" />
<Ellipse Canvas.ZIndex="2" />
正如我在网络上的各个位置所发现的那样-这是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.