Controlling rendering order (ZOrder) in Silverlight without using the Canvas control

我的梦境 提交于 2019-12-23 09:27:53

问题


I'm programmatically adding a UserControl to another in Silverlight 2 by adding it to the parent control's "Children" collection. At first this works fine. If I do something else to the window (in my case I'm scrolling the entire panel out of view then back into view) then it apparently changes the render order and causes my control to be behind the others. I'm searching for a way to control this behavior, to force my window to be on top. The Canvas control has a ZOrder property that allows you to set this, but I am not using a Canvas, I'm using Grids.

I've played with using Children.Insert and messing with the index and that changes the render order as well, but that seems like a kludgey way to address the issue. How can I force my control to be on top?

--Matt


回答1:


In a Grid, the ZOrder should be dictated by the order or the Children. Position 0 being at the bottom, position 1 being on top of position 0 and so on.

I'm not sure I agree that you can use Canvas.ZIndex with a grid - it's an attached property of the Canvas, so would only be available if your Grid where in a Canvas.

http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.zindex(VS.95).aspx




回答2:


Canvas.ZIndex will work for a Grid (and any other control derived from UIElement).

As you can see from http://msdn.microsoft.com/en-us/library/bb979730(VS.95).aspx Anything that derives from UIElement (the base class for all rendered elements in Silverlight) supports the Canvas.ZIndex property, as well as Canvas.Top and Canvas.Left.




回答3:


You should be able to use Canvas.ZIndex in a Grid, it's actually misnamed and should be Panel.ZIndex but it should work.



来源:https://stackoverflow.com/questions/569751/controlling-rendering-order-zorder-in-silverlight-without-using-the-canvas-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!