私は非常にjavascriptedされるSilverlightアプリケーションを作成しています。Javascript/Silverlightプロキシダブルロード遅延
JSの相互作用を可能にするために、私は以下のSLクラス作成しました:これはJavascriptであるとして、しかし
public App()
{
this.Startup += this.onStartup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
// register javascript bridge proxy
// (must register in constructor so proxy is available immediatly)
HtmlPage.RegisterScriptableObject("JsProxy", new JavaScriptProxy());
}
:
[ScriptableType]
public class JavaScriptProxy
{
private string _version;
// provided for testing SL-JS integration
[ScriptableMember]
public void SmokeTest() { HtmlPage.Window.Alert("Hello world!"); }
}
そして、メインSLアプリケーションのコンストラクタにそれをロードします - ヘビーアプリ、それはjavascript自体を介してロード可能でなければなりません。
I.e.何かアロング:SilverlightのonLoadイベントは、このようにJsProxyフィールドが使用できない、発射されるまでagApp.Content.JsProxy
が完全には利用できないので、
// called on body.onLoad
function init() {
var proxy;
var el = document.getElementById("target_canvas");
Silverlight.createObject(..., el, "agApp" ..., {
onLoad: function() {
proxy = agApp.Content.JsProxy;
// ***this line is ok***
proxy.SmokeTest();
}
});
// ***this line fails (of course)***
proxy.SmokeTest();
}
ただし、これはエラーを発生させます。
Silverlightインスタンスを作成すると、すぐににアクセスできるようにするにはどうすればよいですか? while(_mutex);おそらく悪い考えです。
Silverlightアプリケーションインスタンスの作成時に別の抽象化レイヤーが作成されるため、関数はすべてのSLコンテンツを同期して一度に読み込む必要があります。