我正在为一个学校项目做一个十字路口。 我有 4 条车道,其中有一个矩形作为在其上行驶的汽车。 问题是 1 号车和 2 号车在十字路口下行驶,
Panel.ZIndex
似乎不起作用。
XAML 看起来像这样:
<grid>
<canvas> //this is the 1st lane
<rectangle x:Name= "blauweAuto" /> //this is the 1st car
</canvas>
<canvas> //this is the 2nd lane
<rectangle /> //this is the 2nd car
</canvas>
<canvas> //this is the 3th lane
<rectangle /> //this is the 3th car
</canvas>
<canvas> //this is the 4th lane
<rectangle /> //this is the 4th car
</canvas>
</grid>
在四张画布重叠的十字路口(黄色中间)。第一个绘制的车道(画布 1 和 2)的汽车在道路下方行驶。所以我假设它们是分层在其他画布下面的。我尝试了 Zindex,但从我在网上读到的内容来看,它只适用于相同对象的子对象。有什么想法吗?
仅供参考,我每条车道使用一张画布来更轻松地移动汽车
private void BeweegBlauweAuto(double snelheid)
{
blauweAuto.RenderTransform = new TranslateTransform(blauweAuto.RenderTransform.Value.OffsetX + snelheid,0);
}
//DipatcherTimer triggers this event
private void TimerEvent(object sender, EventArgs e)
{
BeweegBlauweAuto(10);
}
将 ZIndex 放入
<canvas>
元素而不是 <rectangle>
元素中。
所有画布元素都是 <grid>
元素的子元素,因此它们的 ZIndex 将被共享。