load silverlight controls in asp.net page

☆樱花仙子☆ 提交于 2020-01-06 08:31:20

问题


I have a silverlight project which contains 2 silverlight controls Control_1 and Control_2. Please note that its in same app.Now I have asp.net project which will use any of these silverlight control (either Control_1 or Control_2).

Challenge is how do I tell silverlight which control to load. I used param property in html object to pass the parameters and tell the app which control to load at runtime?

But what if there are more than 2 controls in same project? We cannot have a long switch case statement in the app file only to load the controls. Is there any better way?


回答1:


No, There isn't, and this is not about Silverlight itself, this is normal logic.

In your App.xaml file, put this:

using System.Windows; // Application, StartupEventArgs

namespace SilverlightApplication
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Specify the main application UI
            if(SomeCondition == true)
                this.RootVisual = new Control1();
            else
                this.RootVisual = new Control2();

            // In the same way, you may define a switch statment
        }
    }
}

You may decide what that condition is by passing parameters to the XAP file, and finally you access those by accessing e.InitParams in Application_Startup

For more info: Application.RootVisual



来源:https://stackoverflow.com/questions/4860154/load-silverlight-controls-in-asp-net-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!