Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Render FrameworkElements on custom control delivered from Panel
3 replies. Latest Post by forci on March 11, 2009.
(0)
forci
Member
351 points
275 Posts
03-07-2009 1:57 AM |
I have a custom control MyControl which derivered from Panel. Averything works as it should be. I go through Childrens and measure them, arrange them, ... ALL OK.
Now i want to add one rectangle to my control. But this Rectangle is not render if it is not one of the Children. Can someone please tell me, if i am missing something. Do i must tell the SL system somehow, that this Rectangle is part of the Panel and it must be render.
And please don't tell me, that this can not be done.
private Rectangle fRect = new Rectangle(); public MyControl() { fRect.Width = 100; fRect.Height = 100; fRect.Stroke = new SolidColorBrush(Colors.Black); fRect.StrokeThickness = 2; fRect.Fill = new SolidColorBrush(Colors.Yellow); //Children.Add(fRect); //if i uncomment this line, the control will be rendered } protected override Size MeasureOverride(Size availableSize) { fRect.Measure(availableSize); ...... } } protected override Size ArrangeOverride(Size finalSize) { fRect.Arrange(new Rect(30, 30, 100, 100)); .....
fullsail...
Contributor
3699 points
829 Posts
03-07-2009 2:26 AM |
Yes, you have to call Add to the control's children collection. Otherwise, how is it supposed to "know" to be rendered?
03-07-2009 2:31 AM |
Actually forci, I think I see what you're trying to do now. Here is what I think is happening: fRect is being rendered, (behind the MyControl) but because you don't have it inside of that Children collection, it has no idea what order to render -- that is how Silverlight renders -- it checks the Children collection of the Panel first, renders all of the Children and then renders the Panel last. But in your case, you just want it rendered above the Panel, so see if you can just manually specify a Z value for fRect, (a value that would allow it to be rendered above your MyControl Panel), and you should then see it. (But honestly, I would just add it as a child. :P
03-11-2009 1:09 PM |
Well setting z-index to 10000 didn't helped, but i redesign my idea.
Thanks