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
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.
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
You should be able to use Canvas.ZIndex in a Grid, it's actually misnamed and should be Panel.ZIndex but it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With