In silverlight
Im trying to assign the RootVisual
object from another class.
The reason for this is that JavaScript will be performing some Ajax
queries and will need to dynamically change the UI element
at any time.
Here is what I have done so far, it doesn't seem to work.
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;
}
Here is my 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);
}
}
Here is the JS that calls the Scriptable myClas
function _test()
{
slControl = document.getElementById("SilverlightControl");
slControl.Content.jsMyClass.SetVisual(1);
}