在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);
}