私は別のクラスからオブジェクトsilverlight
を割り当てようとしています。RootVisual
これは、JavaScript がいくつかのクエリを実行し、いつでもAjax
を動的に変更する必要があるためです。UI element
これが私がこれまで行ってきたことですが、うまくいかないようです。
public class MyClass
{
private UIElement _rootVisual;
public MyClass(UIElement root)
{
_rootVisual = root;
}
public bool SetVisual(int id)
{
switch(id) {
case 0:
this._rootVisual = new MyUI1();
break;
default:
this._rootVisual = new MyUI2();
break;
}
return true;
}
ここに私のApp.xaml.csがあります
private void Application_Startup(object sender, StartupEventArgs e)
{
// Create A Scriptable object
this.myclass= new MyClass( this.RootVisual );
// Register Scriptable for JS Interop
HtmlPage.RegisterScriptableObject("jsMyClass", myclass);
//Load the initial UI but should be able to access/change later via JS
myclass.LoadScene(0);
}
}
Scriptable myClas を呼び出す JS は次のとおりです。
function _test()
{
slControl = document.getElementById("SilverlightControl");
slControl.Content.jsMyClass.SetVisual(1);
}