Skip to main content

Microsoft Silverlight

Answered Question What is the order: SilverlightPlugin.OnPluginLoaded, App.Application_Startup and Page.Page_Loaded and MyCustomControl.OnApplyTemplateRSS Feed

(0)

mkariv
mkariv

Member

Member

60 points

26 Posts

What is the order: SilverlightPlugin.OnPluginLoaded, App.Application_Startup and Page.Page_Loaded and MyCustomControl.OnApplyTemplate

Here is the setup.

3 Projects - one for SL application, one for the hosting Web site, one for the custom control. So the App only has one Page, the default. Page xaml has the custom control I created. The custom control is skinnable using Style with the Tempalte Setter. The custom control is also scriptable. Web site has an ASPX page that uses Silverlight plugin to download the XAP. The idea is that the SL control can be "drawn at" from Javascript.Therfor, the ASPX page also has some javascript logic to "draw" on the control.

The way I wired it is this. the plugin OnPluginLoaded calls the Javascript function that gets the reference to the scriptable class and calls the drawing functions.

The effect is NullReferenceException. That is because inside the control RootElement was not yet instantiated. That is because MyCustomControl.OnApplyTemplate has not yet been called. it is inside OnApplyTemplate I instantiate ElementRoot

ElementRoot = GetTemplateChild(ElementRootName) as FrameworkElement;

So here is the short question: what shold I do? How do I make sure the page controls are all loaded before the javascript layers kicks in. If anything else fails, I'll wire up a MyConstomControl.Ready event to some Javascript function.


The long question - what is the inner mechanics? I assumed without actually knowing, that plugin loads, it downloads the XAP, creates teh App, hence App.App() is called, then it somehow calls Application_Startup and Page() gets created, where its Loaded event is routed to Page_Loaded handler

public Page()

{

InitializeComponent();

this.Loaded += new RoutedEventHandler(Page_Loaded);

}

I further assumed it is only then the event is fired to trigger Javascript.

 

 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: What is the order: SilverlightPlugin.OnPluginLoaded, App.Application_Startup and Page.Page_Loaded and MyCustomControl.OnApplyTemplate

Hello, the order is: SilverlightPlugin.OnPluginLoaded, Application.Startup, Page.Loaded, and finally, Control.OnApplyTemplate. So in your case, yes, you should create a custom event to use in JavaScript after OnApplyTemplate is completed.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities