Silverlight 1.0 and OnLoad

Michael Schwarz on Friday, June 1, 2007

There are some changes for the OnLoad event handler from older beta versions (code name WPF/E). In Silverlight 1.0 beta you will use following event handler, now:

function handleLoad(control, userContext, rootElement){
<span class="rem">// Add your code here</span>
} </pre>

The first argument is a reference to the host control, so there is no need to call sender.getHost() inside the load handler.

Second argument is the user context which is a simple string that you can pass with the properties when instantiating the control with createSilverlight().

Last parameter will be a reference to the root element hosted by the Silverlight control.

The createSilverlight() call looks now like this:

<pre class="csharpcode">function createSilverlight()
{
Sys.Silverlight.createObject(<br> <span class="str">"test.xaml"</span>,
document.getElementById(<span class="str">"WpfeControl1Host"</span>), <br> <span class="str">"wpf"</span>,
{
width:<span class="str">"100%"</span>, height:<span class="str">"100%"</span>,
inplaceInstallPrompt:<span class="kwrd">false</span>, background:<span class="str">'white'</span>,
isWindowless:<span class="str">'true'</span>, framerate:<span class="str">'30'</span>, version:<span class="str">'0.95'</span>,
enableHtmlAccess:<span class="str">'true'</span>
},
{onError:<span class="kwrd">null</span>, onLoad:MyLoad},
<span class="kwrd">null</span>,
{text:<span class="str">"my user context"</span>}
);
}
</pre>

For the userContext in the documentation I found: "userContext of type Object". Until today the userContext is only loop through, so you can use any object, string or whatever you need.