如何控制网格的Z顺序
|
我有以下代码:
TextBlock tmp = new TextBlock
{
Text = displayText,
Foreground = new SolidColorBrush(Colors.Red),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 30
};
Grid grd = new Grid();
grd.Children.Add(tmp);
// grd.Background = new SolidColorBrush(Colors.LightGray);
Viewbox vb = new Viewbox();
vb.Child = grd;
vb.Width = width;
vb.Height = height;
DrawingCvs.Children.Add(vb);
Canvas.SetLeft(vb, xpos);
Canvas.SetTop(vb, ypos);
Canvas.SetZIndex(grd, 1000);
// we need a second grid for cosmetic reasons. Due to
// how the viewbox works, when we resize we lose the full
// width of the grid which has a textblock in it
Grid cosmeticGrd = new Grid
{
Width = width,
Height = height,
Background = new SolidColorBrush(Colors.LightGray)
};
DrawingCvs.Children.Add(cosmeticGrd);
Canvas.SetLeft(cosmeticGrd, xpos);
Canvas.SetTop(cosmeticGrd, ypos);
Canvas.SetZIndex(grd, 0);
我想要的是代码中首先添加的网格位于第二添加的网格上方。我的Z-Index属性设置在这里有什么问题?或者是别的什么?
InB4更改将它们添加到代码中的顺序-是的,我知道这一点,但是作为一个理解点,我想了解ZIndex属性。
没有找到相关结果
已邀请:
1 个回复
场竟矩喘崩
错误地将设置应用到
而不是
。它应该是:
因为
是
的子代 同样,您的第二个
跟注:
应用于错误的
。它应该是:
总之,附加的“ 12”个属性会影响“ 7”个孩子的排序。