0

私は別のクラスからオブジェクト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);
}
4

1 に答える 1

1

私が行う方法は、ルート ビジュアルを同じに保ちながら、その中のコンテンツを変更することです。

したがって、App.csファイルでこれを行います

            //Setup a root content user control so we can swap out the content depending on what we want to show
        UserControl RootContent = new UserControl();
        RootContent.HorizontalAlignment = HorizontalAlignment.Stretch;
        RootContent.VerticalAlignment = VerticalAlignment.Stretch;
        DispatcherHelper.Initialize();
        this.RootVisual = RootContent;
        (this.RootVisual as UserControl).Content = new SplashScreenView();

そして、別のビューに切り替えたいときは、これを行うだけです

(App.Current.RootVisual as UserControl).Content = new Views.PreQualView();
于 2014-03-26T11:13:06.823 に答える