views:

339

answers:

2

I'm working on porting an app from WPF to Silverlight.

The app uses custom types derived from FrameworkElement (in WPF) to describe shapes, and text to be rendered on a Canvas.

The WPF app root node overrides OnRender() to iterate through a collection of 'child' nodes, calling Render on each child node to build the Visual Tree.

Silverlight doesn't expose OnRender, but there are hints that the same effect can be achieved using ControlTemplate.

Is this the way to go, and are there any good examples of using this method available? I've done some googling (binging?) and found nothing really conclusive.

+1  A: 

There's no direct replacement for OnRender, but if you read http://msdn.microsoft.com/en-us/library/dd351483(v=VS.95).aspx, you'll see that MeasureOverride and ArrangeOverride give you control over the visual tree within your control.

Gabe
Thanks @gabe. I found other links related to that, but didn't find that one.
John Weldon
such as http://blogs.msdn.com/silverlight_sdk/archive/2008/10/24/loaded-event-timing-in-silverlight.aspx
nyxtom
I found OnApplyTemplate from the above link which looks like what I want: http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.onapplytemplate(VS.95).aspx
John Weldon
+1  A: 

What Gabe said, but there is an event that occurs when Silverlight is finished "Rendering" called CompositionTarget.Rendering:

http://msdn.microsoft.com/en-us/library/system.windows.media.compositiontarget.rendering(VS.95).aspx

It is the closest analog to "OnRenderFrameComplete"

I would still suggest using the Measure and Arrange overrides, since they are the "right" way to do it.

JerKimball
Thanks @JerKimball
John Weldon