Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 997
Matthew Timbs Avatar asked Feb 20 '09 14:02

Matthew Timbs


3 Answers

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.

like image 61
Peter Richards Avatar answered Oct 18 '22 11:10

Peter Richards


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

like image 32
dwynne Avatar answered Oct 18 '22 11:10

dwynne


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

like image 22
Bill Reiss Avatar answered Oct 18 '22 13:10

Bill Reiss