Skip to main content

Microsoft Silverlight

Answered Question Render FrameworkElements on custom control delivered from PanelRSS Feed

(0)

forci
forci

Member

Member

351 points

275 Posts

Render FrameworkElements on custom control delivered from Panel

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. Smile

        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));
            .....

Make love not war.

fullsailrick
fullsail...

Contributor

Contributor

3699 points

829 Posts

Re: Render FrameworkElements on custom control delivered from Panel

Yes, you have to call Add to the control's children collection. Otherwise, how is it supposed to "know" to be rendered?

fullsailrick
fullsail...

Contributor

Contributor

3699 points

829 Posts

Answered Question

Re: Render FrameworkElements on custom control delivered from Panel

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

forci
forci

Member

Member

351 points

275 Posts

Re: Re: Render FrameworkElements on custom control delivered from Panel

Well setting z-index to 10000 didn't helped, but i redesign my idea.

Thanks

Make love not war.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities